<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi guys,</div><div class=""><br class=""></div><div class="">It would be awesome if with this evolution, we could also auto-write equality operators for enum with equatable payloads.</div><div class=""><br class=""></div><div class="">Today, considering this enum</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> SimpleEnum {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> case1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> case2</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">the condition&nbsp;<span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">SimpleEnum</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">case1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> == </span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">SimpleEnum</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">case1&nbsp;</span>compiles and return true.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">But if the enum has a payload</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> EnumWithPayload {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> integer(value: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> float(value: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">the condition&nbsp;<span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">EnumWithPayload</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">integer</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(value: 1) == </span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">EnumWithPayload</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">integer</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(value: 1)&nbsp;</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;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">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;" class="">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;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">Jerome</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div>
&gt; Good point.<br class="">&gt; <br class="">&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 class="">&gt; <br class="">&gt; This would work much like the Haskell Eq class.<br class="">&gt; <br class="">&gt; &gt; On Sep 12, 2016, at 12:03 PM, Robert Widmann&lt;devteam.codafi at <a href="http://gmail.com" class="">gmail.com</a>&gt;wrote:<br class="">&gt; &gt; <br class="">&gt; &gt; 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 (<a href="https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift#L24&lt;https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift#L24&gt;" class="">https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift#L24&lt;https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/Stream.swift#L24&gt;</a>) 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).<br class="">&gt; &gt; <br class="">&gt; &gt; ~Robert Widmann<br class="">&gt; &gt; <br class="">&gt; &gt; 2016/09/10 8:24、Daniel Tartaglia via swift-evolution&lt;swift-evolution at <a href="http://swift.org" class="">swift.org</a>&lt;mailto:swift-evolution at <a href="http://swift.org" class="">swift.org</a>&gt;&gt;のメッセージ:<br class="">&gt; &gt; <br class="">&gt; &gt; &gt; Now that Swift 3 is out the door, I’m going to float this proposal again…<br class="">&gt; &gt; &gt; <br class="">&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/&lt;https://www.andrewcbancroft.com/2015/07/01/every-swift-value-type-should-be-equatable/&gt;" class="">https://www.andrewcbancroft.com/2015/07/01/every-swift-value-type-should-be-equatable/&lt;https://www.andrewcbancroft.com/2015/07/01/every-swift-value-type-should-be-equatable/&gt;</a><br class="">&gt; &gt; &gt; And that many, if not most, value types consist of properties that are value types.<br class="">&gt; &gt; &gt; Then the language should make it easy to conform to the Equatable protocol.<br class="">&gt; &gt; &gt; <br class="">&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 class="">&gt; &gt; &gt; <br class="">&gt; &gt; &gt; Implementing == in such cases is tedious boilerplate that the compiler should be able to infer on its own.<br class="">&gt; &gt; &gt; <br class="">&gt; &gt; &gt; Does anybody want to help me write up an official proposal?<br class="">&gt; <br class="">&gt; <br class="">&gt;<span class="Apple-converted-space">&nbsp;</span>

</body></html>