I was surprised (Int,Int) isn't Hashable. How do I write the obvious extension to make it so?
If I try "extension (Int,Int)" the error is that non-nominal type (Int,Int) can't be extended. The word "nominal" appears nowhere in the Swift iBooks provided by Apple, so I can't be absolutely certain that I even know what Xcode is telling here... Using a typealias gives the same error.
How do I extend (Int,Int) to make it Hashable so I can use it for dictionary keys?
What is a "non-nominal" type, and where can I find that definition?
You cannot extend tuple types in Swift.
The term "nominal" is not clearly defined, but usually it is used when you mean `something identifiable by its name` in a context of speaking about programming language.
Another example of non-nominal type is function type. You cannot extend function types neither.
typealias CallbackType = (Int)->Void
extension CallbackType { //->Non-nominal type 'CallbackType' (aka '(Int) -> ()') cannot be extended
//...
}
And nominal types are class, struct, enum and protocol.
One reason why you cannot extend tuple types is described in the Swift Book.
NOTE
Tuples are useful for temporary groups of related values. They’re not suited to the creation of complex data structures. If your data structure is likely to persist beyond a temporary scope, model it as a class or structure, rather than as a tuple. For more information, see Structures and Classes.
Seems the designers of Swift want to limit tuples in very limited use cases and do not want to expand it.
There was once (maybe more) a discussion to make tuples Hashable, but the responses from the core members of Swift team are negative.
Synthesizing Equatable, Hashable, and Comparable for tuple types
(forums.swift.org/t/synthesizing-equatable-hashable-and-comparable-for-tuple-types/7111)