<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Well in that case I find even more confusing that to implement equality you have to define a function which is different from the operator.<br></div><div><br>On 08 Dec 2015, at 18:43, Richard Fox <<a href="mailto:fox.ios.dev@gmail.com">fox.ios.dev@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">I dont see how this makes it less readable, are you taking into consideration that you still use == everywhere for comparison, after defining with isEqual? As this method would be defined in the stdlib.<br><blockquote type="cite"><blockquote type="cite"><div dir="ltr"><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6px;padding:0px;margin:0px;border-radius:3px;word-break:normal;border:0px;display:inline;max-width:initial;overflow:initial;line-height:inherit;word-wrap:normal;background-image:initial;background-position:initial;background-repeat:initial">public func == <T : Equatable>(lhs: T, rhs: T) -> Bool </code></pre></div></blockquote></blockquote><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 8, 2015 at 5:36 AM David Hart <<a href="mailto:david@hartbit.com">david@hartbit.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Your proposition makes comparison code much less readable only for a small benefit at the point of definition. I'd vote against.</div></div><div dir="auto"><div><br>On 08 Dec 2015, at 11:06, Nicky Gerritsen via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div>
Although I like the idea, I think it should be more general, as this
same reasoning also holds for other operators.<br>
Wouldn't it be better to allow to define operators within a type? So
that we can just implement == in the type?<br>
<br>
I do not know how hard it is to implement it or if this is even
possible. Probably it is hard, because otherwise it would already
have been done?<br>
<pre cols="72">Regards,
Nicky</pre>
<div>On 12/08/2015 11:01 AM, Richard Fox via
swift-evolution wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<h3><span style="font-size:16px;line-height:25.6px;font-weight:normal">Hi
all,</span><br>
</h3>
<p>I would like to
propose changing the Equatable protocol to use <code>isEqual(to:Self)
-> Bool</code>, defined inside of a type to replace the
currently used operator <code>==</code> function,
which is defined outside of the type.</p>
<h3><a href="https://gist.github.com/Nadohs/308603afa65cbbfba07c#reasoning" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1.2;background-color:transparent" target="_blank"><span style="font-weight:normal;font-stretch:normal;font-size:16px;line-height:1;font-family:octicons;display:inline-block;color:rgb(0,0,0);vertical-align:middle"></span></a>Reasoning:</h3>
<ol>
<li>Having the conforming
function defined inside of the type is more intuitive, since
in general functions required for conformance are defined
within the type. It feels like an unnecesary detail for
learners of Swift to have to stumble through.</li>
</ol>
<p>The implementation
for this would look something like this:</p>
<pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6px;padding:0px;margin:0px;border-radius:3px;word-break:normal;border:0px;display:inline;max-width:initial;overflow:initial;line-height:inherit;word-wrap:normal;background:transparent"> public protocol Equatable{
....
/// Shortcut for defining `==` function inside type definition.
@warn_unused_result
func isEqual(to:Self) -> Bool
}
@warn_unused_result
public func == <T : Equatable>(lhs: T, rhs: T) -> Bool {
return lhs.isEqual(rhs)
}
</code></pre>
<h3><a href="https://gist.github.com/Nadohs/308603afa65cbbfba07c#impact-on-existing-code" style="color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1.2;background-color:transparent" target="_blank"><span style="font-weight:normal;font-stretch:normal;font-size:16px;line-height:1;font-family:octicons;display:inline-block;color:rgb(0,0,0);vertical-align:middle"></span></a>Impact
on Existing Code:</h3>
<p>This implementation
would break existing code, but could be fixed with a default
protocol extension such as:</p>
<pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;padding:16px;border-radius:3px;word-wrap:normal;color:rgb(51,51,51);background-color:rgb(247,247,247)"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6px;padding:0px;margin:0px;border-radius:3px;word-break:normal;border:0px;display:inline;max-width:initial;overflow:initial;line-height:inherit;word-wrap:normal;background:transparent"> /// Default `isEqual` function to satisfy other types only definiting
/// `==` for equality.
public extension Equatable{
func isEqual(to:Self) -> Bool{
return self == to
}
}
</code></pre>
<p>Not
adding the default function for <code>isEqual</code> makes
more sense to me though, since it would remove any strict
requirement for Equatable conformance and leave no warning for
the loop you would create by implementing neither <code>isEqual</code> nor <code>==</code>.<br>
<br>
Regards,<br>
Rich Fox</p>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RHl2la-2BftHBRgU0PDt5l8enF-2FEQjC5JypuWCzFZiX9RFxTQ-2BMiLiXWVDri-2FqZ9JkpZYRyntAD5jDorctLW3ieg6VPkteLjD3FEN-2FKRo0WrLD1wpmOa7FzqmnIGlfXAu5ENo5Rp7dwXhSjXq5AfIMpfKl5LKljZaicWmxHb5T87j-2Bt-2BSsySAGP4rHwB5kkwh4Iux3jWEmK2pYJ9qD29vNPE6rw-2FxjVTQrk2SE3ZsGXZ4-3D" alt="" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" height="1" width="1" border="0">
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
swift-evolution mailing list
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>
</pre>
</blockquote>
<br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43hXwizS3O2z60WweqomIrdiby1oM0uSRtxZF1S8eVPCcMS3Ztj9I1zTsCG3bdH5TePR-2Ft5S8biBvfes30cYJ3yuc0ADzxg1xjwSEmgCtnIEv09AUXvmtMVBEC5cyVAYAUuYHrD-2BkLrorXL-2Fd3bPYUSJ0qlOrhZTW2263yhLyxV9F6IaXf87TehxIgJFkIqpFvA-3D-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></blockquote></div></div>
</div></blockquote></body></html>