[swift-evolution] [Draft][Proposal] Formalized Ordering

Dave Abrahams dabrahams at apple.com
Fri Jul 22 21:23:37 CDT 2016

on Fri Jul 22 2016, Brent Royal-Gordon <brent-AT-architechies.com> wrote:

>> On Jul 22, 2016, at 4:55 PM, Daniel Duan via swift-evolution <swift-evolution at swift.org> wrote:
>>> Well, it's still a very real question whether we ought to have the
>>> additional API surface implied by areSame, or wether we should collapse
>>> it with ===.
>> To spell this out (because I had to think about it for a second): === will be derived from
>> <=>, but also becomes default implementation for ==, which remains open for customization.
>> I like this idea. If we keep === as a separate thing, now users have 3 “opportunities” to define
>> equality. The must be few, if any, use cases for this.
>> Would love to see if anyone on the list can give us an example. Otherwise we should make
>> areSame === again™!
> If `===` is the new `areSame`, and `Hashable` is based on `===`,
> wouldn't that mean that objects could only be hashed (and thus, be
> looked up in Dictionary and Set) by identity? So, for instance, code
> like this:
> 	var set = Set<NSString>()
> 	set.insert("test")
> 	set.insert("test")
> 	print(set.count)
> Would print "2"? Or worse, might print "1" or "2" depending on the
> details of how Swift generates literals and Foundation implements
> short strings?
> Am I the only one who thinks that's a problem?

No, NSString's conformance to Identifiable (probably NSObject's,
actually) would define `===` in terms of `isEqual()`.  That's saying
identity for these types is determined by `isEqual()`.


More information about the swift-evolution mailing list