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

Jaden Geller jaden.geller at gmail.com
Fri Jul 22 21:04:13 CDT 2016


> 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?

I was under the impression that the identity of an `NSObject` would use the existing `isEqual:` method. That is, identity doesn't necessarily mean reference identity anymore.

> On Jul 22, 2016, at 7:00 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> 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?
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list