Again, +1 to Tony&#39;s analysis. In the context of numerics in particular, global functions and operators are very much &quot;normal means,&quot; and if anything instance methods are rather &quot;convenience.&quot;<br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 26, 2016 at 13:36 Tony Allevato via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Apr 26, 2016 at 11:29 AM Nicola Salmoria &lt;<a href="mailto:nicola.salmoria@gmail.com" target="_blank">nicola.salmoria@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 26, 2016 at 8:10 PM, Thorsten Seitz <span dir="ltr">&lt;<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div></div><div>See inline.</div><div><br>Am 26.04.2016 um 19:36 schrieb Nicola Salmoria via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 26, 2016 at 4:28 PM, Tony Allevato <span dir="ltr">&lt;<a href="mailto:allevato@google.com" target="_blank">allevato@google.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span><div dir="ltr">On Sun, Apr 24, 2016 at 2:57 AM Nicola Salmoria via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">&gt; &gt; func isEqual(to other: Self) -&gt;Bool<br>
&gt; &gt; func isLess(than other: Self) -&gt;Bool<br>
&gt; &gt; func isLessThanOrEqual(to other: Self) -&gt;Bool<br>
&gt;<br>
&gt; I&#39;m still not sure why these are methods instead of operators.<br>
<br>
I think this is an *excellent* choice, and I hope it is the first step to completely removing operators from protocols.<br>
<br>
IMHO throwing operators into protocols is inconsistent and confusing. Having regular methods and a single generic version of the operator that calls down on the type’s methods is clearer and guarantees that generic code can avoid ambiguities by calling the methods directly, instead of having to rely only on heavily overloaded global operators.<br></blockquote><div><br></div></span><div>I personally disagree on this point. To me, a protocol describes a set of requirements for a type to fulfill, which includes things other than methods. Just as a protocol can define initializers, properties, and associated types that a type must define in order to conform, it makes sense that a protocol would also define which operators a conforming type must support.</div></div></div></blockquote><div><br></div><div>Well, I&#39;m not sure about that. A protocol describes what a type can do, so it&#39;s debatable whether a global function is within this scope.<br><br></div><div>Operators are magically special: you can declare them inside a protocol and require them to be available for conformance, even if they don&#39;t belong to the type. You can&#39;t do the same thing for normal global functions, yet conceptually global functions and operators are the same thing.<br></div><br><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>Introducing a mapping between names and operators poses a few problems:</div><div><br></div><div>– IMO, they are overly verbose and add noise to the definition. This makes the language look less clean (I&#39;m getting visions of NSDecimalNumber).</div><div>– They expose two ways to accomplish the same thing (writing `x.isEqual(to: y)` and `x == y`).</div></div></div></blockquote></div></div></div></div></blockquote><div><br></div><div>That is my concern with this approach as well. </div><div><br></div><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>– Do certain operators automatically get mapped to method names with appropriate signatures across all types, or does a conforming type still have to provide that mapping by implementing the operators separately? If it&#39;s the latter, that&#39;s extra work for the author of the type writing the protocol. If it&#39;s the former, does it make sense to automatically push these operators for all types? Should any type that has an `add` method automatically get `+` as a synonym as well? That may not be desirable.</div></div></div></blockquote><div><br></div><div>The difference at the protocol declaration is between:<br><br>protocol Equatable {<br>    func ==(lhs: Self, rhs: Self) -&gt; Bool<br>}<br></div><div><br>and:<br><br>protocol Equatable {<br>    func isEqual(to other: Self) -&gt; Bool<br>}<br><br>func ==&lt;T: Equatable&gt;(lhs: T, rhs: T) -&gt; Bool {<br>    return lhs.isEqual(to: rhs)<br>}<br></div><div><br></div><div>so the latter is a bit more verbose, but arguably clearer in intent, and not different from how you would define any generic global function using a protocol, or from how you can define protocol extensions with default implementations that take advantage of the protocol&#39;s core methods.<br></div></div></div></div></div></blockquote><div><br></div>The problem is that it is no longer clear whether to use the method or the operator to check for equality. <div><br></div><div>Now if we had some access modifier to hide the isEqual method except for overwriting it and using it within the operator, maybe some variant of &#39;protected&#39; (e.g. visible in implementors and the same file as the protocol) then that approach would be fine.</div><div><br></div><div>-Thorsten </div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Why would you want to do that?<br><br></div><div>I see operators mostly as a convenience: a shortcut to express in a more concise way something which should also be available through normal means.<br></div></div></div></div></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>Why is the operator not the &quot;normal means&quot;? Centuries of mathematics tell us that &quot;2 + 2 == 4&quot;, not &quot;2.adding(2).isEqual(to: 4)&quot;. We should make it easier and consistent for Swift authors to write code that conforms to existing terms (or in this case, symbols) of art, not introduce a completely new and arbitrary set of methods that (1) bloat public interfaces and (2) map to the same operators anyway.</div></div></div><div dir="ltr"><div class="gmail_quote"><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>It could be argued that generic code might prefer, for clarity, to use explicit methods instead of vague global operators.<br><br></div><div>The approved but still unimplemented<br><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0042-flatten-method-types.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0042-flatten-method-types.md</a><br>also applies here, since the isEqual member method could also be used as a static method for increased symmetry and clarity, i.e. instead of<br><br></div><div>_ = x.isEqual(to: y)<br><br></div><div>one could do<br><br></div><div>_ = Equatable.isEqual(x, to: y)<br></div><div><br></div><div>this could be useful in case of ambiguities.<br><br></div><div>Nicola<br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><br></div><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>The difference for the conformance is between:<br></div><div><br></div><div>extension Foo : Equatable { }<br></div><div><br>func ==(lhs: Foo, rhs: Foo) -&gt; Bool {<br>    return &lt;comparison&gt;<br>}<br><br></div><div>and:<br><br></div><div>extension Bar : Equatable {<br>    func isEqual(to: Bar) -&gt; Bool {<br>        return &lt;comparison&gt;<br>    }<br>}<br></div><div><br></div><div>the former way to define the conformance can be confusing to newbies. The latter is straightforward and consistent with the usual way to adopt a protocol.<br><br></div><div>The == operator looks exactly the same at its use points, but the way how it&#39;s implemented is different.<br>In the former case, it&#39;s many overloads of a global function, which can stress the compiler&#39;s type inference and doesn&#39;t offer an obvious way to disambiguate in case of ambiguities.<br></div><div>In the latter case, there is only one generic definition of ==, which automatically applies to all types that conform to the protocol.<br></div><div> <br></div><div>Nicola<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>I&#39;m very supportive of the floating-point protocol proposal in general, but I feel the arithmetic and comparison operations should be exposed by operators alone and not by methods, where there is a suitable operator that has the intended meaning.</div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5"> </span><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
—<br>
Nicola<br>
<br>
_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>
</blockquote></div><br></div></div>
</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></div></blockquote></div></div></div></blockquote></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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>