On Fri, Apr 29, 2016 at 2:49 PM, Nate Cook via swift-evolution < [email protected]> wrote:
> > On Apr 29, 2016, at 1:57 PM, Wolfgang H. via swift-evolution < > [email protected]> wrote: > > > > Inconsistency A. is that “Set” currently is the only collection type > conforming to protocol 'Hashable'”. IMHO both “Array” and “Dictionary” > should conform to protocol “Hashable”, too. > > Set is the only Hashable* collection type because it's the only collection > type where all of its values are always Hashable themselves. Array<Element> > can be an array of a non-Hashable type; Dictionary<Key: Value> can have a > non-Hashable type for Value. If/when Swift gains conditional protocol > compliance, arrays and dictionaries of Hashable types could themselves be > Hashable, but not until then. > > > Inconsistency B. is that “Array<Int>” is typesafe if used as element of > an “Array” but is non-typesafe if used as element of “Set” or “Dictionary”. > The non-typesafety may result from the mapping of “Array<Int>” to “NSArray“. > > Since Array<Element> isn't Hashable, you can't create a Set<Array<Int>>. > The type system therefore falls back to using the bridged Objective-C type > for Array<Int>, which can provide a hash value based on object identity. > > Nate > > > *For my spell checker's sake, could we rename Hashable to Washable? Thanks Well put, Nate. It will be a great day when conditional protocol compliance comes to Swift. Until then, there's good reason why Array and Dictionary can't be washed.
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
