<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Jul 9, 2017, at 10:06, David Baraff via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 9, 2017, at 8:27 AM, Jens Persson <<a href="mailto:jens@bitcycle.com" class="">jens@bitcycle.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">(Also, note that your implementation of == uses lhs === rhs thus will only return true when lhs and rhs are the same instance of SomeClass.)</div></div></blockquote><div>Of course — i threw that in just to make a simple example.</div><div><br class=""></div><div>Followup question: what I really wanted to write was an == operator for a tree:</div><div><br class=""></div><div>// silly tree, useful for nothing</div><div>class Tree : Equatable {</div><div> let rootData:Int</div><div> let children:[(String, Tree)]</div><div><br class=""></div><div> static public func ==(_ lhs:Tree, _ rhs:Tree) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return lhs.rootData == rhs.rootData && </div><div> lhs.children == rhs.children<span class="Apple-tab-span" style="white-space:pre">                </span>// sadly, this doesn’t compile</div><div> }</div><div>}</div></div></blockquote><br><div>Right, the `==` func is *defined* for 2-element tuples where both elements conform to `Equatable`, but that tuple type doesn't itself *conform* to `Equatable`. So the<span style="background-color: rgba(255, 255, 255, 0);">`==` func that's defined on "Array where Element: Equatable" can't see it.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">We'd need both "conditional conformance" and "tuple conformance" in order for that to Just Work.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">- Dave Sweeris </span></div></body></html>