<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=""><blockquote type="cite" class="">On Jan 30, 2016, at 11:03 PM, Vanderlei Martinelli via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Since the first public betas I’d like to know why operator implementation have to be written outside the body of its owner.<div class=""><br class=""></div><div class="">Take as example the code:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class=""><span style="color:rgb(116,137,31)" class="">protocol</span> MyEquatable {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(116, 137, 31);" class=""><span style="color:rgb(80,111,116)" class="">&nbsp; &nbsp; </span>@warn_unused_result</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">func</span> ==(lhs: <span style="color:rgb(215,96,27)" class="">Self</span>, rhs: <span style="color:rgb(215,96,27)" class="">Self</span>) -&gt; <span style="color:rgb(251,153,3)" class="">Bool</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class=""><span style="color:rgb(116,137,31)" class="">struct</span> MyStruct: <span style="color:rgb(18,101,182)" class="">MyEquatable</span> {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">let</span> foo: <span style="color:rgb(251,153,3)" class="">String</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">let</span> bar: <span style="color:rgb(251,153,3)" class="">String</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class=""><span style="color:rgb(116,137,31)" class="">func</span> ==(lhs: <span style="color:rgb(255,147,0)" class="">MyStruct</span>, rhs: <span style="color:rgb(255,147,0)" class="">MyStruct</span>) -&gt; <span style="color:rgb(251,153,3)" class="">Bool</span> {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">return</span> lhs.<span style="color:rgb(14,123,195)" class="">foo</span> == rhs.<span style="color:rgb(14,123,195)" class="">foo</span> &amp;&amp; lhs.<span style="color:rgb(14,123,195)" class="">bar</span> == rhs.<span style="color:rgb(14,123,195)" class="">bar</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116); min-height: 17px;" class=""><br class=""></div></div><div class="">Why we cannot write:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class=""><span style="color:rgb(116,137,31)" class="">protocol</span> MyEquatable {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(116, 137, 31);" class=""><span style="color:rgb(80,111,116)" class="">&nbsp; &nbsp; </span>@warn_unused_result</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">func</span> ==(lhs: <span style="color:rgb(215,96,27)" class="">Self</span>, rhs: <span style="color:rgb(215,96,27)" class="">Self</span>) -&gt; <span style="color:rgb(251,153,3)" class="">Bool</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class=""><span style="color:rgb(116,137,31)" class="">struct</span> MyStruct: <span style="color:rgb(18,101,182)" class="">MyEquatable</span> {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">let</span> foo: <span style="color:rgb(251,153,3)" class="">String</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">let</span> bar: <span style="color:rgb(251,153,3)" class="">String</span></div><p style="margin:0px;font-size:12px;line-height:normal;font-family:'Input Mono';color:rgb(80,111,116);min-height:17px" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">func</span> ==(lhs:&nbsp;<span style="color:rgb(255,147,0)" class="">MyStruct</span>, rhs:&nbsp;<span style="color:rgb(255,147,0)" class="">MyStruct</span>) -&gt; Bool {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:rgb(116,137,31)" class="">return</span> lhs.foo == rhs.foo &amp;&amp; lhs.bar == rhs.bar</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Input Mono'; color: rgb(80, 111, 116); min-height: 17px;" class=""><br class=""></div></div><div class="">Any thoughts?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-Van</div></div></div></blockquote><br class=""></div>+1. I’ve been meaning to write up something about this for some time. The thing I’d change is to include only the right-hand side as an argument, and use ‘self’ to refer to the left-hand side:<div class=""><br class=""></div><div class=""><div class="">struct MyStruct: MyEquatable {</div><div class="">&nbsp; &nbsp; let foo: String</div><div class="">&nbsp; &nbsp; let bar: String</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; func ==(other: MyStruct) -&gt; Bool {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return self.foo == other.foo &amp;&amp; self.bar == other.bar</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class="">Charles</div><div class=""><br class=""></div></div></body></html>