<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 30, 2016, at 9:03 PM, Vanderlei Martinelli 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="">Since the first public betas I’d like to know why operator implementation have to be written outside the body of its owner.</div></div></blockquote><div><br class=""></div><div>Yep, this is a generally desirable feature (at least for symmetric operators). &nbsp;This would also be great to get dynamic dispatch of operators within class declarations. &nbsp;I don’t think we have a firm proposal nailing down how name lookup works with this though.</div><div><br class=""></div><div>-Chris</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><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 class=""><br class=""></div></div>
_______________________________________________<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=""></body></html>