[swift-evolution] Equatable auto-write func == Proposal

Daniel Tartaglia danielt1263 at gmail.com
Mon Sep 12 12:23:41 CDT 2016


Good point.

The real push here is that when the programmer *does* declare a type Equatable and the op == has an obvious implementation, that the programmer shouldn’t have to manually implement it him/herself. This would apply only to types that have been declared Equatable and that consist of exclusively properties which have all also been declared Equatable.

This would work much like the Haskell Eq class.

> On Sep 12, 2016, at 12:03 PM, Robert Widmann <devteam.codafi at gmail.com> wrote:
> 
> Please be careful when wording this proposal.  You want derived conformances, but don't obscure that message with the claim that every type admits a useful Equatable instance. It is most certainly not the case that every value type has a useful (read [mostly]: decidable) equality.  A few counterexamples, the type of lazy streams (https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift#L24 <https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift#L24>) requires infinite space to evaluate a useful answer.  The type of functions [without a modulus of continuity] also don't admit a useful, or even canonical, equality (in Swift at least).  
> 
> ~Robert Widmann
> 
> 2016/09/10 8:24、Daniel Tartaglia via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> のメッセージ:
> 
>> Now that Swift 3 is out the door, I’m going to float this proposal again…
>> 
>> Given that every value type should be equatable (rational here): https://www.andrewcbancroft.com/2015/07/01/every-swift-value-type-should-be-equatable/ <https://www.andrewcbancroft.com/2015/07/01/every-swift-value-type-should-be-equatable/>
>> And that many, if not most, value types consist of properties that are value types.
>> Then the language should make it easy to conform to the Equatable protocol.
>> 
>> In other words, if I declare my value type as Equatable, and it is exclusively composed of value types that are already equatable, then implementing the actual == function should be optional (or maybe even forbidden.)
>> 
>> Implementing == in such cases is tedious boilerplate that the compiler should be able to infer on its own.
>> 
>> Does anybody want to help me write up an official proposal?

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


More information about the swift-evolution mailing list