<div dir="ltr">Good idea! For the syntax I suggest something like this:<div><br></div><div><blockquote type="cite" style="font-size:13px"><span class="im"><div dir="ltr"><font face="monospace, monospace"><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)"><span style="color:rgb(116,137,31)">protocol</span> MyEquatable {</div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(116,137,31)"><span style="color:rgb(80,111,116)">    </span>@warn_unused_result</div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)">    <span style="color:rgb(116,137,31)">operator</span> ==(lhs: <span style="color:rgb(215,96,27)">Self</span>, rhs: <span style="color:rgb(215,96,27)">Self</span>) -&gt; <span style="color:rgb(251,153,3)">Bool</span></div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)">}</div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116);min-height:17px"><br></div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)"><span style="color:rgb(116,137,31)">struct</span> MyStruct: <span style="color:rgb(18,101,182)">MyEquatable</span> {</div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)">    <span style="color:rgb(116,137,31)">let</span> foo: <span style="color:rgb(251,153,3)">String</span></div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)">    <span style="color:rgb(116,137,31)">let</span> bar: <span style="color:rgb(251,153,3)">String</span></div><p style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116);min-height:17px">    <br></p><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)">    <span style="color:rgb(116,137,31)">operator</span> ==(lhs: <span style="color:rgb(255,147,0)">MyStruct</span>, rhs: <span style="color:rgb(255,147,0)">MyStruct</span>) -&gt; Bool {</div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)">        <span style="color:rgb(116,137,31)">return</span> lhs.foo == rhs.foo &amp;&amp; lhs.bar == rhs.bar</div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116)">    }</div><div style="margin:0px;font-size:12px;line-height:normal;color:rgb(80,111,116);min-height:17px">}<br></div></font></div></span></blockquote><div><br></div><div><font face="monospace, monospace">`operator`</font> meaning <font face="monospace, monospace">`static func`</font></div><div><br></div></div><div><br></div><div>-Van</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 31, 2016 at 11:14 AM, Haravikk <span dir="ltr">&lt;<a href="mailto:e-mail@haravikk.me" target="_blank">e-mail@haravikk.me</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Definitely a +1 from me for the feature.</div><div><br></div><div>What are the name lookup issues? Do you mean cases where an operator for Foo == Foo exists in more than one location? Personally I’d just stick with what we have now, i.e- treat operator implementations within a specific class/struct as being globally defined anyway and throw an error if the same signature is declared more than once.</div><div><br></div><div>One minor issue around putting them in class/struct bodies though is that I wonder if perhaps a keyword other than func should be used? While they are functions, they aren’t methods of instances. At the very least they should probably need to be static.</div><div><div class="h5"><br><div><blockquote type="cite"><div>On 31 Jan 2016, at 05:26, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div><br>On Jan 30, 2016, at 9:03 PM, Vanderlei Martinelli via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr">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></div><div>Yep, this is a generally desirable feature (at least for symmetric operators).  This would also be great to get dynamic dispatch of operators within class declarations.  I don’t think we have a firm proposal nailing down how name lookup works with this though.</div><div><br></div><div>-Chris</div><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>Take as example the code:</div><div><br></div><div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)"><span style="color:rgb(116,137,31)">protocol</span><span> </span>MyEquatable {</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(116,137,31)"><span style="color:rgb(80,111,116)">   <span> </span></span>@warn_unused_result</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">func</span><span> </span>==(lhs:<span> </span><span style="color:rgb(215,96,27)">Self</span>, rhs:<span> </span><span style="color:rgb(215,96,27)">Self</span>) -&gt;<span> </span><span style="color:rgb(251,153,3)">Bool</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">}</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116);min-height:17px"><br></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)"><span style="color:rgb(116,137,31)">struct</span><span> </span>MyStruct:<span> </span><span style="color:rgb(18,101,182)">MyEquatable</span><span> </span>{</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">let</span><span> </span>foo:<span> </span><span style="color:rgb(251,153,3)">String</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">let</span><span> </span>bar:<span> </span><span style="color:rgb(251,153,3)">String</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">}</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116);min-height:17px"><br></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)"><span style="color:rgb(116,137,31)">func</span><span> </span>==(lhs:<span> </span><span style="color:rgb(255,147,0)">MyStruct</span>, rhs:<span> </span><span style="color:rgb(255,147,0)">MyStruct</span>) -&gt;<span> </span><span style="color:rgb(251,153,3)">Bool</span><span> </span>{</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">return</span><span> </span>lhs.<span style="color:rgb(14,123,195)">foo</span><span> </span>== rhs.<span style="color:rgb(14,123,195)">foo</span><span> </span>&amp;&amp; lhs.<span style="color:rgb(14,123,195)">bar</span><span> </span>== rhs.<span style="color:rgb(14,123,195)">bar</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">}</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116);min-height:17px"><br></div></div><div>Why we cannot write:</div><div><br></div><div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)"><span style="color:rgb(116,137,31)">protocol</span><span> </span>MyEquatable {</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(116,137,31)"><span style="color:rgb(80,111,116)">   <span> </span></span>@warn_unused_result</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">func</span><span> </span>==(lhs:<span> </span><span style="color:rgb(215,96,27)">Self</span>, rhs:<span> </span><span style="color:rgb(215,96,27)">Self</span>) -&gt;<span> </span><span style="color:rgb(251,153,3)">Bool</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">}</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116);min-height:17px"><br></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)"><span style="color:rgb(116,137,31)">struct</span><span> </span>MyStruct:<span> </span><span style="color:rgb(18,101,182)">MyEquatable</span><span> </span>{</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">let</span><span> </span>foo:<span> </span><span style="color:rgb(251,153,3)">String</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">let</span><span> </span>bar:<span> </span><span style="color:rgb(251,153,3)">String</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116);min-height:17px">    <br></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">   <span> </span><span style="color:rgb(116,137,31)">func</span><span> </span>==(lhs: <span style="color:rgb(255,147,0)">MyStruct</span>, rhs: <span style="color:rgb(255,147,0)">MyStruct</span>) -&gt; Bool {</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">       <span> </span><span style="color:rgb(116,137,31)">return</span><span> </span>lhs.foo == rhs.foo &amp;&amp; lhs.bar == rhs.bar</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">    }</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116);min-height:17px"><br></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116)">}</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(80,111,116);min-height:17px"><br></div></div><div>Any thoughts?</div><div><br></div><div><br></div><div>-Van</div><div><br></div></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br></div></div></div></blockquote></div><br></div>