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

Austin Zheng austinzheng at gmail.com
Wed Mar 9 02:30:51 CST 2016


As Brent pointed out, adding this sort of support opens a whole can of worms. Large parts of the standard library would silently become unsound.

As well, in my experience people who have had trouble using (e.g.) Equatable with heterogeneous collections are often trying to do type-unsound things. Maybe Swift should support a separate notion of heterogenous equality for comparisons between Equatable types (and one of the POP WWDC talks actually sketched out an outline of how this might be done), but that's different from making Equatable universal. In addition, I think Swift 3's proposed support for conditional protocol conformance will make creating principled heterogeneous collections easier, which should ease some of the burden.

Best,
Austin

> On Mar 9, 2016, at 12:17 AM, David Hart <david at hartbit.com> wrote:
> 
> 
> On 08 Mar 2016, at 23:15, Austin Zheng via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> I would prefer Equatable and Hashable to remain opt-in, and for us to add better support for automatic deriving of implementation.
> 
> On 08 Mar 2016, at 23:57, Zach Waldowski via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> I completely agree with Austin here. Automatic derivation (perhaps through the same mechanisms Joe is talking about) would be a nice enhancement, but I find it refreshing and advantageous for simple value types to have very little automatic behavior.
> 
> Pedantically I agree with both of you, but from a very pragmatic point of you, I think it's very important to point out what Joe said about how this could reduce one of the most frustrating aspects of Swift, when people work with heterogeneous arrays and try to conform to Equatable:
> 
>> that would solve many of the common problems people currently have trying to work with heterogeneous containers.
> 
> 
> 

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


More information about the swift-evolution mailing list