[swift-evolution] Universal Equatability, Hashability, and Comparability

Austin Zheng austinzheng at gmail.com
Fri Mar 11 00:36:10 CST 2016


I took Joe's points about making it easier to work with heterogeneous collections to refer to heterogeneous comparison.

I'm still -1 to "func ==<T>(lhs: T, rhs: T) -> Bool", but for the reasons Brent brought up earlier. If adding a default conformance can be made "as easy as" declaring conformance to "Equatable" without an explicit impl (or declaring conformance to "Regular" or "#derives(Equatable)" or ...), I see that as the preferable option:

- The amount of inconvenience it gives the programmer is negligible - one conformance declaration for each custom type that deserves to be equatable, and no function or operator code.
- Declaring it explicitly is a flag that the programmer has intentionally decided that this type should be equatable under whatever common-sense default rules the compiler uses for the type's 'kind'. This is especially important for APIs being vended out, whose implementations might be opaque to the user.
- Declaring a universal homogenous equality operator that works for types for which equality makes no sense (or there's no clear definition) is actively hostile to users of the language (to go back to Brent's point, "why is my Set<() -> Int> broken when I try using it?")

Austin

> On Mar 10, 2016, at 10:21 PM, William Dillon <william at housedillon.com> wrote:
> 
> 
>> On Mar 10, 2016, at 9:58 PM, Thorsten Seitz via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>> Am 09.03.2016 um 22:34 schrieb Austin Zheng via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
>> 
>>> I think we might (at least partially) be in violent agreement :). Most (if not everyone) on this thread has agreed that painless opt-in auto-conformance is a good thing ("struct Foo : Regular { .. }"), albeit with differing definitions of 'painless'. But I maintain that having a "func ==(lhs: Any, rhs: Any) -> Bool" stdlib fallback implementation of == is a lot of potential pain for very little benefit.
>> 
>> I agree completely. Not having everything comparable with everything is a good thing IMO!
>> 
> 
> I can’t tell if I misunderstood Joe's original proposal, but I don’t think the suggestion was to have everything comparable to everything, but to have any type comparable with itself by default.  I’m against everything being comparable with everything else, but for having a default equality for every type with itself.
> 
> To re-state:
> 
> -1 to: func ==(lhs: Any, rhs: Any) -> Bool
> +1 to: func ==<T> (lhs: T, rhs: T) -> Bool
> 
> - Will
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160310/06f95b3e/attachment.html>


More information about the swift-evolution mailing list