<div dir="ltr"><div><div>+1 for making enums with payloads Equatable by default. Right now this requires lots of copy-paste boiler plate that can easily result in bugs.<br><br></div>As for the general struct case, I think there could be a default implementation but we should be able to overwrite `==` if we need to. Doesn&#39;t seem sensible to me comparing several inner objects and arrays if a single `uuid` would suffice.<br><br></div>Francisco<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 19, 2016 at 3:15 PM, Jérôme Duquennoy via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Hi guys,</div><div><br></div><div>It would be awesome if with this evolution, we could also auto-write equality operators for enum with equatable payloads.</div><div><br></div><div>Today, considering this enum</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#0433ff">enum</span><span> SimpleEnum {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>  </span><span style="color:#0433ff">case</span><span> case1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>  </span><span style="color:#0433ff">case</span><span> case2</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">the condition <span style="color:rgb(52,149,175)">SimpleEnum</span><span>.</span><span style="color:rgb(52,149,175)">case1</span><span> == </span><span style="color:rgb(52,149,175)">SimpleEnum</span><span>.</span><span style="color:rgb(52,149,175)">case1 </span>compiles and return true.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">But if the enum has a payload</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#0433ff">enum</span><span> EnumWithPayload {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>  </span><span style="color:#0433ff">case</span><span> integer(value: </span><span style="color:#3495af">Int</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>  </span><span style="color:#0433ff">case</span><span> float(value: </span><span style="color:#3495af">Float</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">the condition <span style="color:rgb(52,149,175)">EnumWithPayload</span><span>.</span><span style="color:rgb(52,149,175)">inte<wbr>ger</span><span>(value: 1) == </span><span style="color:rgb(52,149,175)">EnumWithPayload</span><span>.</span><span style="color:rgb(52,149,175)">integer</span><span>(value: 1) </span>does not compile: operator == does not exist for that type.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">Hand-writing this missing equality operator turns out to be pretty fastidious and error prone, notably because you might prefer to not use a “default” case, to take advantage of the completeness check of the compiler.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">So you have to write n * (n-1) cases and that can be a lot of cases !</div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">Jerome</div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div>
&gt; Good point.<br>&gt; <br>&gt; 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.<br>&gt; <br>&gt; This would work much like the Haskell Eq class.<br>&gt; <br></span>&gt; &gt; On Sep 12, 2016, at 12:03 PM, Robert Widmann&lt;devteam.codafi at <a href="http://gmail.com" target="_blank">gmail.com</a>&gt;wrote:<br>&gt; &gt; <br>&gt; &gt; Please be careful when wording this proposal. You want derived conformances, but don&#39;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 (<a href="https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift#L24%3Chttps://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift%23L24%3E" target="_blank">https://github.com/typelift/<wbr>Swiftz/blob/swift-develop/<wbr>Swiftz/Stream.swift#L24&lt;https:<wbr>//github.com/typelift/Swiftz/<wbr>blob/swift-develop/Swiftz/<wbr>Stream.swift#L24&gt;</a>) requires infinite space to evaluate a useful answer. The type of functions [without a modulus of continuity] also don&#39;t admit a useful, or even canonical, equality (in Swift at least).<br>&gt; &gt; <br>&gt; &gt; ~Robert Widmann<br>&gt; &gt; <br>&gt; &gt; 2016/09/10 8:24、Daniel Tartaglia via swift-evolution&lt;swift-<wbr>evolution at <a href="http://swift.org" target="_blank">swift.org</a>&lt;mailto:<a href="mailto:swift-evolution" target="_blank">swift-<wbr>evolution</a> at <a href="http://swift.org" target="_blank">swift.org</a>&gt;&gt;のメッセージ:<span class=""><br>&gt; &gt; <br>&gt; &gt; &gt; Now that Swift 3 is out the door, I’m going to float this proposal again…<br>&gt; &gt; &gt; <br></span>&gt; &gt; &gt; Given that every value type should be equatable (rational here): <a href="https://www.andrewcbancroft.com/2015/07/01/every-swift-value-type-should-be-equatable/%3Chttps://www.andrewcbancroft.com/2015/07/01/every-swift-value-type-should-be-equatable/%3E" target="_blank">https://www.andrewcbancroft.<wbr>com/2015/07/01/every-swift-<wbr>value-type-should-be-<wbr>equatable/&lt;https://www.<wbr>andrewcbancroft.com/2015/07/<wbr>01/every-swift-value-type-<wbr>should-be-equatable/&gt;</a><span class=""><br>&gt; &gt; &gt; And that many, if not most, value types consist of properties that are value types.<br>&gt; &gt; &gt; Then the language should make it easy to conform to the Equatable protocol.<br>&gt; &gt; &gt; <br>&gt; &gt; &gt; 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.)<br>&gt; &gt; &gt; <br>&gt; &gt; &gt; Implementing == in such cases is tedious boilerplate that the compiler should be able to infer on its own.<br>&gt; &gt; &gt; <br>&gt; &gt; &gt; Does anybody want to help me write up an official proposal?<br>&gt; <br>&gt; <br>&gt;<span> </span>

</span></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>