<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>To make sure I understand correctly, what you are discussing is having == be auto generated in some way for types. The automatic implementation of == would be a member wise logical and operation:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">struct Person {</div><div id="AppleMailSignature"> let age: Int</div><div id="AppleMailSignature"> let name: String</div><div id="AppleMailSignature">} deriving Equatable</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Would also generate:</div><div id="AppleMailSignature">func ==(left: Person, right: Person) -> Bool {</div><div id="AppleMailSignature"> return left.age == right.age && left.name == right.name;</div><div id="AppleMailSignature">}</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">The compiler would only do this if all data members implement (or derive) the Equatable protocol, and probably error otherwise.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">That's my interpretation. If I misunderstood, please correct me. </div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">As it stands, I think something like this is a fabulous idea, as I have recently found myself writing lots of member wise equality checks.</div><div id="AppleMailSignature"><br><div>Donald Pinckney</div><div><br></div>Sent from my iPhone</div><div><br>On Feb 13, 2016, at 9:12 AM, Donnacha Oisín Kidney via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8">In Haskell, when you declare a datatype, you can follow it with a “deriving” clause, and it will derive several typeclasses (which are Haskell’s equivalent to protocols):<div class=""><br class=""></div><div class=""><span style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;" class="">data</span><span style="font-size: 11px; font-family: Menlo;" class=""> </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;" class="">Person</span><span style="font-family: Menlo; font-size: 11px;" class=""> = </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;" class="">Person</span><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(49, 44, 221); font-family: Menlo; font-size: 11px;" class="">{</span><span style="font-family: Menlo; font-size: 11px;" class=""> name </span><span style="color: rgb(49, 44, 221); font-family: Menlo; font-size: 11px;" class="">::</span><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;" class="">String</span><span style="color: rgb(49, 44, 221); font-family: Menlo; font-size: 11px;" class="">,</span><span style="font-family: Menlo; font-size: 11px;" class=""> age </span><span style="color: rgb(49, 44, 221); font-family: Menlo; font-size: 11px;" class="">::</span><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;" class="">Int</span><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(49, 44, 221); font-family: Menlo; font-size: 11px;" class="">}</span><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;" class="">deriving</span><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;" class="">Eq</span></div><div class=""><br class=""></div><div class="">In Swift, I’d imaging the equivalent would be something like:</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: #bb2ca2" class="">struct</span> Person {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> name: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> age: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">} deriving <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Equatable</span></div></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 13 Feb 2016, at 17:04, Patrick Gili via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Not having a lot of experience with Haskell, can you provide an example, so that we can better understand what you're proposing?<br class=""><br class="">Cheers,<br class="">-Patrick<br class=""><br class=""><blockquote type="cite" class="">On Feb 12, 2016, at 3:47 PM, Daniel Tartaglia via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">In Haskell, we can mark a data block as deriving from Eq and it will auto-generate the == operator.<br class=""><br class="">I would like to see Swift auto-generate the == operator if a struct implements Equatable. Obviously, it would only be able to do this if all the structs members implemented Equatable themselves.<br class=""><br class="">Has this idea already been proposed? I didn’t see it at the github repo…<br class=""><br class="">Thanks,<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>