<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 Oct 25, 2017, at 5:29 AM, David Zarzycki via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; 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; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 25, 2017, at 02:34, Xiaodi Wu via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Please see earlier replies summarizing core team members' persuasive arguments as to why not multiple protocol hierarchies like this.</div></div></blockquote></div><br class=""><div class="">Hi Xiaodi,</div><div class=""><br class=""></div><div class="">The above line is does it help your argument. Even if a person was motivated to search through the entire mailing list archives looking for said arguments, they won’t be able to guess which arguments you found to be persuasive (and who was sufficiently “core” at the time, no less). Can you please provide URLs into the archives? Is that a big ask?</div></div></div></blockquote><br class=""></div><div>If I'm (now) reading this correctly, he put the argument itself at the end of his earlier reply to you:</div><div><br class=""></div><div><blockquote type="cite" class=""><div class="">On Oct 24, 2017, at 7:04 PM, Xiaodi Wu via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Tue, Oct 24, 2017 at 4:28 PM, David Zarzycki&nbsp;<span dir="ltr" class="">&lt;<a href="mailto:dave@znu.io" target="_blank" class="">dave@znu.io</a>&gt;</span>&nbsp;wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><span class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 24, 2017, at 14:55, Ben Cohen via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="m_-4265814734774014143Apple-interchange-newline"><div class=""><div class="">There really is no way to square this circle. Every option is going to have downsides. We have to balance correctness, least surprise/most expected behavior for most people, and consistency. For me, making generic use of Equatable and Comparable stick to the documented conformance generically, while keeping FP-specific uses the way they are, is the least bad option.&nbsp;</div></div></blockquote></div><br class=""></span><div class="">Hi Ben,</div><div class=""><br class=""></div><div class="">Out of curiosity, what do you think about breaking Equatable into two protocols: Equatable and Substitutable? The former would be defined in terms of mathematics, while the latter is simple to define and usable by collections, etc. For example, while +0 equals -0, they are not substitutable (because 1.0 / +0.0 == +inf BUT 1.0 / -0.0 == -inf). In the case of NaNs, substitutability would depend on the NaN payload being the same or not (because some later subsystem might interpret the NaN payload).</div></div></blockquote><div class="">&nbsp;<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class="">Finally, and unless I’m missing something, floating-point “substitutability” would translate to bitwise equality at the hardware level, which is nice from a performance perspective.</div></div></blockquote><div class=""><br class=""></div><div class="">As Steve pointed out, floating-point "substitutability" as you define it is unlikely to be desired in most contexts; differentiation by NaN payload or by decimal value representation is highly unintuitive, and it would be intolerable for generic `.contains(.nan)` to sometimes return true and sometimes false depending on NaN payload.</div><div class="">&nbsp;</div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><br class=""></div><div class="">On the topic of sorting, we could do the same thing, where we break Comparable into two protocols: Comparable and Sortable. The former would be defined in terms of mathematics, while the latter has no mathematical obligation and therefore values like +0 and -0 can be consistently sorted. The same goes of NaNs with payloads (they can be sorted). And finally, at the hardware level, this should be quite efficient because of how the floating point bits are laid out (in that an integer comparison of FP bits should work for this Sortable proposal).</div><div class=""></div></div></blockquote></div><br class=""></div><div class="gmail_extra">Floating point values can certainly be consistently sorted as an sequence of bits, but again, it is unlikely that anyone would want such a sort of their floating point values.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">But as to the topic of splitting protocols, it is essentially the design adopted by Rust. During discussion of Ben's original proposal, some core team members argued very eloquently against such a design based on what's happened in Rust. Namely:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">- If Float is not Equatable but instead SomethingOtherThanEquatable (in Rust, it's called `PartialEq`), then we will have officially done our job in terms of stdlib semantic guarantees. However, in practice, people *want* to write generic algorithms that work with both integers and floating point values.</div><div class="gmail_extra">- Based on the Rust experience, what people will do when they realize that Float doesn't conform to Equatable is instead to write generic algorithms that operate on SomethingOtherThanEquatable while assuming that integer `==` and floating point `==` will work the same way.</div><div class="gmail_extra">- The result is that you now have two protocols instead of one, but most people still use only one--and still use it incorrectly. The existing problem has simply been transferred from Equatable to SomethingOtherThanEquatable. The new Equatable accomplishes nothing in terms of helping people write better code.</div></div></div></blockquote><div class=""><div class=""><br class=""></div></div></div><div>I just didn't catch that that was "the" argument the first time I read it.</div><div><br class=""></div><div><div>I guess I don't understand why this is persuasive... Seems to me that even if every relevant generic function that ever ships has it's parameter conform to "SomethingOtherThanEquatable" instead of "Equatable", the extra protocol&nbsp;<i class="">has</i>&nbsp;done something: it's made the programmer acknowledge, on some level, that they might not always get a sensical result from comparing two values of that type. Neither "MostlyEquatable" nor "PartialEq" are particularly scary, so maybe they aren't the best names... If you had to constrain your generic parameters like "T: EquatableIfYouAreOKWithBridgesFallingDownAndEveryoneDying" to get the function to work with floating point types, then it'd probably get your attention.</div><div><br class=""></div><div>Moreover, I'd argue that what I called "MaybeEquatable" and "MaybeComparable", where all the ops return `Bool?`,&nbsp;is the correct semantics for FP comparisons; it's just that most (all?) hardware doesn't support anything analogous to `Optional` (and AFAIK, neither did any programming languages at the time IEEE-754 was created), so there wasn't a way for the IEEE committee to actually express that idea.</div><div><br class=""></div>I don't see another way out of it... IEEE floats have partial ordering/eq -- AFAICT it's inherently incorrect for them to conform to a protocol that, for <i class="">all</i> other conforming types, has total ordering/eq semantics. That said, I fully acknowledge that this is all above my pay grade (also I hadn't realized that the issue was as settled as it apparently is). If splitting the protocols is a no-go from the get go, I'll go back to trying to figure out a better way to handle it without doing that.</div><div class=""><br class=""></div>- Dave Sweeris</body></html>