<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 Dec 11, 2015, at 9:00 AM, Frederick Kellison-Linn <<a href="mailto:fred.kl@me.com" class="">fred.kl@me.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Chris,</div><div class=""><br class=""></div>Thanks for the response, I’m glad to hear that. Is this something that is planned/feasible for Swift 3?</div></div></blockquote><div><br class=""></div><div>It’s desired, but not considered critical for Swift 3, so it will depend on how times work out. If ABI stability ends up taking more time than expected, it will probably get pushed out.</div><div><br class=""></div><div>-Chris</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">FKL</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 11, 2015, at 1:02 AM, Chris Lattner <<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Dec 8, 2015, at 10:32 PM, Frederick Kellison-Linn via swift-evolution <</span><a href="mailto:swift-evolution@swift.org" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">swift-evolution@swift.org</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Currently, implementing an ‘<font face="SourceCodePro-Regular" class="">==</font>‘ function for a custom class can be somewhat cumbersome. In the simple hierarchy:<div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(170, 35, 145);">class<span class=""><span class="Apple-converted-space"> </span>A {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">var</span><span class="Apple-converted-space"> </span>a:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(92, 38, 153);">Int</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">init</span>(<span class="" style="color: rgb(170, 35, 145);">_</span><span class="Apple-converted-space"> </span>a:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(92, 38, 153);">Int</span>) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">self</span>.<span class="" style="color: rgb(79, 129, 135);">a</span><span class="Apple-converted-space"> </span>= a</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro'; min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"><span class="" style="color: rgb(170, 35, 145);">class</span><span class="Apple-converted-space"> </span>B :<span class="Apple-converted-space"> </span><span class="" style="color: rgb(64, 110, 116);">A</span><span class="Apple-converted-space"> </span>{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">var</span><span class="Apple-converted-space"> </span>b:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(92, 38, 153);">Int</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">init</span>(<span class="" style="color: rgb(170, 35, 145);">_</span><span class="Apple-converted-space"> </span>b:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(92, 38, 153);">Int</span>,<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">_</span><span class="Apple-converted-space"> </span>a:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(92, 38, 153);">Int</span>) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">self</span>.<span class="" style="color: rgb(79, 129, 135);">b</span><span class="Apple-converted-space"> </span>= b</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">super</span>.<span class="" style="color: rgb(170, 35, 145);">init</span>(a)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';">}</div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"><br class=""></div><div class="" style="margin: 0px; line-height: normal;">A reasonable implementation of<span class="Apple-converted-space"> </span><font face="SourceCodePro-Regular" class="">==</font> would seem to be</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Source Code Pro';"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;"><span class="" style="color: rgb(170, 35, 145);">func</span><span class="Apple-converted-space"> </span>==(lhs:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(64, 110, 116);">A</span>, rhs:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(64, 110, 116);">A</span>) -><span class="Apple-converted-space"> </span><span class="" style="color: rgb(92, 38, 153);">Bool</span><span class="Apple-converted-space"> </span>{</div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">return</span><span class="Apple-converted-space"> </span>lhs.<span class="" style="color: rgb(79, 129, 135);">a</span><span class="Apple-converted-space"> </span>== rhs.<span class="" style="color: rgb(79, 129, 135);">a</span></div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;">}</div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal; min-height: 14px;"><br class=""></div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;"><span class="" style="color: rgb(170, 35, 145);">func</span><span class="Apple-converted-space"> </span>==(lhs:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(64, 110, 116);">B</span>, rhs:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(64, 110, 116);">B</span>) -><span class="Apple-converted-space"> </span><span class="" style="color: rgb(92, 38, 153);">Bool</span><span class="Apple-converted-space"> </span>{</div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 35, 145);">return</span><span class="Apple-converted-space"> </span>lhs.<span class="" style="color: rgb(79, 129, 135);">a</span><span class="Apple-converted-space"> </span>== rhs.<span class="" style="color: rgb(79, 129, 135);">a</span><span class="Apple-converted-space"> </span>&&</div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;"> lhs.<span class="" style="color: rgb(79, 129, 135);">b</span><span class="Apple-converted-space"> </span>== rhs.<span class="" style="color: rgb(79, 129, 135);">b</span></div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;">}</div><div class="" style="font-size: 11px; font-family: 'Source Code Pro'; margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;">I’d be interested to know if there is any interest taken in this problem and whether possible solutions have been discussed. If<span class="Apple-converted-space"> </span><font face="SourceCodePro-Regular" class="">==</font> were instead behaved as if it were a method of its first argument (as in a<span class="Apple-converted-space"> </span><font face="SourceCodePro-Regular" class="">.equals(other)</font> method) then the solution above is sufficient to avoid returning the wrong result, but being forced to use <span class="" style="font-family: 'Source Code Pro';">.</span><span class="" style="font-family: 'Source Code Pro'; color: rgb(170, 35, 145);">dynamicType</span><span class="" style="font-family: 'Source Code Pro';"> </span>for something as basic as equality checking seems cumbersome to me.</div></div></div></div></div></div></blockquote><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Hi Frederick,</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">The preferred approach is to allow operators to be defined inside of types. This would allow them to be dynamically dispatched inside of classes.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">-Chris</div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>