<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br></div><div>Am 09.03.2016 um 22:34 schrieb Austin Zheng via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">I think we might (at least partially) be in violent agreement :). Most (if not everyone) on this thread has agreed that painless opt-in auto-conformance is a good thing ("struct Foo : Regular { .. }"), albeit with differing definitions of 'painless'. But I maintain that having a "func ==(lhs: Any, rhs: Any) -&gt; Bool" stdlib fallback implementation of == is a lot of potential pain for very little benefit.</div></div></div></div></blockquote><div><br></div>I agree completely. Not having everything comparable with everything is a good thing IMO!<div><br></div><div>-Thorsten&nbsp;</div><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Austin</div></div><div class="gmail_quote"><br></div><div class="gmail_quote">On Wed, Mar 9, 2016 at 1:17 PM, Dave Abrahams via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><br>
on Tue Mar 08 2016, Brent Royal-Gordon &lt;<a href="http://brent-at-architechies.com">brent-AT-architechies.com</a>&gt; wrote:<br>
<br>
&gt;&gt; - Function types in Swift do not provide a ready equality<br>
&gt; operation. We could provide a default implementation that always<br>
&gt; returns 'false', perhaps.<br>
&gt;<br>
&gt; I think this sort of puts the lie to the idea.<br>
&gt;<br>
&gt; We can always provide *a* definition of equality, but I suspect it<br>
&gt; will often be an *incorrect* definition.<br>
<br>
</span>I disagree; IMO it would seldom be incorrect.<br>
But I wouldn't necessarily want to make everything equatable.&nbsp; I'd want<br>
to give many things an equatable conformance that's available simply by<br>
declaring it. In fact, I'd like to be able to say:<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; struct Something : Regular {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Stored properties that are all Regular<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
<br>
and get Equatable, Comparable, and Hashable for free.</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><br>
&gt; That's why you had to suggest functions should always be false: you<br>
&gt; cannot (without more effort than you want to spend) provide a correct<br>
&gt; definition of equality for it.<br>
&gt;<br>
&gt; I mean, imagine what happens if you make functions Equatable and<br>
&gt; Hashable but with definitions that don't actually work. Currently,<br>
&gt; `Set&lt;Void -&gt; Void&gt;` gives you an error:<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp;error: type 'Void -&gt; Void' does not conform to protocol 'Hashable'<br>
&gt;<br>
&gt; But with this feature in place, Swift would happily produce a Set of<br>
&gt; functions which collides endlessly, doesn't do any uniquing, never<br>
&gt; says it contains any value you pass into it, and can only remove<br>
&gt; elements by index.<br>
&gt;<br>
&gt; A type that is "never equal" completely breaks Set in practice, and<br>
&gt; there's no way for the type system to catch the problem.<br>
&gt;<br>
&gt; If we automatically synthesize a == operator for every type, many of<br>
&gt; those operators will be incorrect. For instance, anything that<br>
&gt; includes a cache will be incorrect.<br>
&gt; Anything that includes a pointer to a buffer and ought to evaluate the<br>
&gt; buffer's contents will be incorrect.<br>
&gt; Anything that includes a closure will be incorrect. Individually, each<br>
&gt; of these cases is minor, but they multiply and interact with each<br>
&gt; other until, together, they undermine confidence in ==.<br>
<br>
</span>These things wouldn't be Regular by themselves.&nbsp; To make them<br>
composable, you can create a single Regular value type that wraps each<br>
one.<br>
<span class=""><br>
&gt; If you explicitly mark things as Equatable, then it is clear that the<br>
&gt; equality operator on them really does have a sensible definition. But<br>
&gt; if you can pass anything into ==, you will never know what will<br>
&gt; actually *work*. If everything's Equatable, then nothing is.<br>
&gt;<br>
&gt; * * *<br>
&gt;<br>
&gt; Auto-deriving is a different story, though, especially if it's opt-in<br>
&gt; (you have to say `deriving Equatable`). There, you presumably have<br>
&gt; looked at the default semantics and determined they're appropriate for<br>
&gt; your type.<br>
<br>
</span>I don't know if that level of explicitness is needed.&nbsp; Explicit<br>
declaration of conformance might be enough.<br>
<span class=""><br>
&gt; But I think it's clear that derived conformances should eventually be<br>
&gt; a user-accessible feature. We already derive RawRepresentable and<br>
&gt; ErrorType on enums. (We also derive initializers on some types, but<br>
&gt; that's arguably a separate feature.) I think it's clear that Swift ∞<br>
&gt; ought to allow you to derive protocol conformances; it's just a matter<br>
&gt; of scheduling.<br>
&gt;<br>
&gt; So I think that what we ought to do is this:<br>
&gt;<br>
&gt; • Make a best guess at what Swift ∞ would want you to do to invoke the<br>
&gt; user-specified derivation logic for an arbitrary protocol—implicit<br>
&gt; derivation or something marked by a keyword.<br>
&gt; • Think about whether derived conformances of Equatable, Hashable,<br>
&gt; and/or Comparable are urgent enough that we should implement them<br>
&gt; before the general feature.<br>
&gt; • If so, design these features along the lines of what we would expect<br>
&gt; the eventual user-specified derivation feature to use.<br>
<br>
</span>Of course.<br>
<span class=""><font color="#888888"><br>
--<br>
-Dave<br>
</font></span><div class=""><div class="h5">_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>
</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">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></body></html>