<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This could be implemented by extending the derived conformance logic in Sema. Right now it only derives Equatable for enums without payload cases, but it would be relatively straightforward to synthesize the obvious Equatable conformance if all payloads are themselves Equatable, or tuples of Equatable types. You would then just write<div class=""><br class=""></div><div class="">extension MyEnumWithPayload : Equatable {}</div><div class=""><br class=""></div><div class="">Ditto for Hashable.</div><div class=""><br class=""></div><div class="">Slava</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 11, 2015, at 8:15 AM, Marc Knaup via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">It's a similar discussion with simple structs which could automatically be equatable.<div class="">And for Hashable.<br class=""><div class="">It's difficult to draw a line where that makes sense and where not.<div class=""><br class=""></div><div class="">In any case I'd prefer to not have recursive equality automatically.</div><div class=""><ul class=""><li class="">It can easily lead to unexpected behavior when you forget to implement an own equality operator in order to remove variables from the equation which do not affect the equality.</li><li class="">You could add another variable to an existing enum (or struct) which is now automatically compared for equality without you noticing and which might be wrong.</li><li class="">You cannot opt out of that behavior.</li></ul></div><div class="">But I agree that the current implementations of the equality operator for enums are awful.</div><div class="">Maybe we can make the enum (or struct) conform to a special protocol which allows it to automatically generate the equality operator (and even default hashValue).</div><div class=""><br class=""></div><div class="">Something like this:</div><div class=""><span class=""><br class=""></span></div><div class=""><font face="monospace, monospace" class=""><span class="">protocol&nbsp;</span></font><span style="font-family:monospace,monospace" class="">DefaultEquatable: Equatable {}</span></div><div class=""><span style="font-family:monospace,monospace" class="">protocol DefaultHashable: Hashable {}</span></div><div class=""><font face="monospace, monospace" class=""><span class=""><br class=""></span></font></div><div class=""><font face="monospace, monospace" class=""><span class="">enum</span><span class=""> MyEnumWithPayload: </span><span class="">DefaultEquatable</span><span class="">, </span><span class="">DefaultHashable</span><span class=""> {<br class=""></span><span class="">&nbsp; &nbsp; case</span><span class=""> One(payload: String)<br class=""></span><span class="">&nbsp; &nbsp; case</span><span class=""> Two(payload: String)<br class="">}</span></font></div><div class=""><br class=""></div></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=NLTid1W7V2mxBEfr5Y3KfTntaxSmOQp5vjACZc9Eh19BsqU-2BFXIWDrf5TDlzGqZnbJpN6BCu-2BXDgamCC28lyGWZkyCLcilXTIuvHM-2FS9VbeSa3ZxY4p0LD0iTo4FDTyjrdJDzBMIyONu7TSghNBYkSSOt-2BOqtuPG4xZuZfYO8-2F68Cvw6GhthuPJTbwessHTbFKvl1NzQ4hL3R9F2WDb9Afmz7NzvNj-2FES1z8jVRAGwc-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>