[swift-dev] Rationalizing FloatingPoint conformance to Equatable

Xiaodi Wu xiaodi.wu at gmail.com
Wed Oct 25 18:25:35 CDT 2017

On Wed, Oct 25, 2017 at 12:06 PM, David Zarzycki <dave at znu.io> wrote:

> On Oct 25, 2017, at 12:01, David Sweeris <davesweeris at mac.com> wrote:
> On Oct 25, 2017, at 5:29 AM, David Zarzycki via swift-dev <
> swift-dev at swift.org> wrote:
> On Oct 25, 2017, at 02:34, Xiaodi Wu via swift-dev <swift-dev at swift.org>
> wrote:
> Please see earlier replies summarizing core team members' persuasive
> arguments as to why not multiple protocol hierarchies like this.
> Hi Xiaodi,
> 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?
> If I'm (now) reading this correctly, he put the argument itself at the end
> of his earlier reply to you:
> Right, to which I replied that I wasn’t proposing the Rust model or your
> similar “MaybeEquatable” model.

The other Dave was proposing such a thing, and that was my reply to him.
You're right that you are proposing something different.

> I was proposing something different where Float and Int are both Equatable
> and Substitutable, but neither Equatable nor Substitutable inherit from the
> other. The former is mathematical and the latter is not (which allows it to
> deal with NaN payloads, ±0, etc). Generic algorithms care mostly if not
> completely about mathematics, while generic containers care mostly if not
> completely about substitutability. They can live alongside each other and
> get along peacefully/sanely. And if people need to care about both, then at
> least they have an out.

The issue with this is similar to that in my reply earlier about bitwise
comparison of floating-point values. Yes, you can propose some total
ordering over floating-point values totally divorced from `==`, but I'm
quite certain that people who invoke `sort()` on an array of floating-point
values don't simply want *some* deterministic order, but rather an actual
increasing order of numeric values. Likewise, when someone asks if an array
contains a floating-point value (say, `10.0 as Decimal`), they generally
want to know if *any* representation of that value exists. The point is
that _what kind of substitutability_ matters, and the kind that people will
expect for floating-point values is the very mathematical substitutability
that is supposed to be guaranteed by Equatable, which simply does not
accommodate NaN.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171025/a33e41fc/attachment.html>

More information about the swift-dev mailing list