<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 Jul 22, 2016, at 9:57 PM, Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">on Fri Jul 22 2016, Xiaodi Wu <</span><a href="http://xiaodi.wu-at-gmail.com/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">xiaodi.wu-AT-gmail.com</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On Fri, Jul 22, 2016 at 9:46 PM, Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><br class="">on Fri Jul 22 2016, Xiaodi Wu <<a href="http://xiaodi.wu-at-gmail.com" class="">xiaodi.wu-AT-gmail.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">On Fri, Jul 22, 2016 at 9:23 PM, Matthew Johnson <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a><br class=""><br class="">wrote:<br class=""><br class=""><blockquote type="cite" class=""><br class="">On Jul 22, 2016, at 9:17 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:<br class=""><br class="">On Fri, Jul 22, 2016 at 9:15 PM, Matthew Johnson via swift-evolution <<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><br class="">On Jul 22, 2016, at 9:04 PM, Dave Abrahams via swift-evolution <<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""><br class="">on Fri Jul 22 2016, Matthew Johnson <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">On Jul 22, 2016, at 8:37 PM, Xiaodi Wu via swift-evolution<br class=""><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">On Fri, Jul 22, 2016 at 8:20 PM, Dave Abrahams via swift-evolution<br class=""><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><br class=""><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>>><br class="">wrote:<br class=""><br class="">on Fri Jul 22 2016, Daniel Duan <<a href="http://daniel-at-duan.org" class="">daniel-AT-duan.org</a><br class=""><<a href="http://daniel-at-duan.org/" class="">http://daniel-at-duan.org/</a>>> wrote:<br class=""><br class="">On Jul 22, 2016, at 3:00 PM, Dave Abrahams via swift-evolution<br class=""><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>>><br class="">wrote:<br class=""><br class=""><br class="">on Fri Jul 22 2016, Daniel Duan<br class=""><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>>>><br class="">wrote:<br class=""><br class=""><br class="">On Jul 22, 2016, at 11:05 AM, Dave Abrahams via swift-evolution<br class=""><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>>>><br class="">wrote:<br class=""><br class=""><br class="">on Thu Jul 21 2016, Duan<br class=""><br class=""><br class=""><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>>>>><br class="">wrote:<br class=""><br class="">Great proposal. I want to second that areSame may mislead user to<br class="">think this is about identity.<br class=""><br class="">I like areEquivalent() but there may be better names.<br class=""><br class=""><br class="">It really *is* about identity as I posted in a previous message. But<br class="">that doesn't change the fact that areEquivalent might be a better name.<br class="">It's one of the things we considered; it just seemed long for no real<br class="">benefit.<br class=""><br class=""><br class="">If the addresses of the arguments aren’t being used, then we don’t<br class="">consider<br class="">them part of their *identity*. I can follow this logic. My fear is most<br class="">users<br class="">won’t make this leap on their own and get the same initial impression<br class=""></blockquote></blockquote></blockquote>as<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">I did.<br class="">It's entirely possible this fear is unfounded. Some educated<br class=""></blockquote></blockquote></blockquote>bikesheding<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">wouldn't hurt here IMO :)<br class=""><br class=""><br class="">Well, it's still a very real question whether we ought to have the<br class="">additional API surface implied by areSame, or wether we should collapse<br class="">it with ===.<br class=""><br class=""><br class="">To spell this out (because I had to think about it for a second): ===<br class="">will be derived from<br class=""><=>,<br class="">but also becomes default implementation for ==, which remains open for<br class="">customization.<br class=""><br class=""><br class="">I was imagining roughly this (untested):<br class=""><br class="">/// Two references are identical if they refer to the same<br class="">/// instance.<br class="">///<br class="">/// - Note: Classes with a more-refined notion of “identical”<br class="">/// should conform to `Identifiable` and implement `===`.<br class="">func ===(lhs: AnyObject, rhs: AnyObject) -> Bool {<br class=""> ObjectIdentifier(lhs) == ObjectIdentifier(rhs)<br class="">}<br class=""><br class="">/// Supports testing that two values of `Self` are identical<br class="">///<br class="">/// If `a` and `b` are of type `Self`, `a === b` means that<br class="">/// `a` and `b` are interchangeable in most code. A conforming<br class="">/// type can document that specific observable characteristics<br class="">/// (such as the `capacity` of an `Array`) are inessential and<br class="">/// thus not to be considered as part of the interchangeability<br class="">/// guarantee.<br class="">///<br class="">/// - Requires: `===` induces an equivalence relation over<br class="">/// instances.<br class="">/// - Note: conforming types will gain an `==` operator that<br class="">/// forwards to `===`.<br class="">/// - Note: Types that require domain-specific `==`<br class="">/// implementations with different semantics (e.g. floating<br class="">/// point) should define a more-specific overload of `==`,<br class="">/// which will be used in contexts where the static type is<br class="">/// known to the compiler.<br class="">/// - Note: Generic code should usually use `==` to compare<br class="">/// conforming instances; that will always dispatch to `===`<br class="">/// and will be unaffected by more specific overloads of<br class="">/// `==`.<br class="">protocol Identifiable { // née Equatable name is negotiable<br class=""> func ===(_: Self, _: aSelf) -> Bool<br class="">}<br class=""><br class="">/// Default definition of `==` for Identifiable types.<br class="">func ==<T: Identifiable>(lhs: T, rhs: T) -> Bool {<br class=""> return lhs === rhs<br class="">}<br class=""><br class="">/// Conforming types have a default total ordering.<br class="">///<br class="">/// If `a` and `b` are of type `Self`, `a <=> b` means that<br class="">/// `a` and `b` are interchangeable in most code. A conforming<br class="">/// type can document that specific observable characteristics<br class="">/// (such as the `capacity` of an `Array`) are inessential and<br class="">/// thus not to be considered as part of the interchangeability<br class="">/// guarantee.<br class="">///<br class="">/// - Requires: `<=>` induces a total ordering over<br class="">/// instances.<br class="">/// - Requires: the semantics of `<=>` are consistent with<br class="">/// those of `===`. That is, `(a <=> b) == .equivalent`<br class="">/// iff `a === b`.<br class=""><br class="">For floating point, I'd hope that `a === b` if `(a <=> b) == .same`<br class=""></blockquote></blockquote></blockquote>*but<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">not iff*. This is to satisfy IEEE 754: "Comparisons shall ignore the<br class=""></blockquote></blockquote></blockquote>sign<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">of zero (so +0 = −0)”.<br class=""><br class=""><br class="">The point of this design is that `===` means identity and that `.same `<br class="">also means identity.<br class=""><br class="">Since this is new territory I suppose we get to decide what identity<br class="">means for floating point. Should +0 and -0 have the same identity or<br class="">not? I’ll leave the answer to folks more knowledgable about numerics<br class="">than I.<br class=""><br class=""><br class="">It's settled law<br class=""><br class=""></blockquote></blockquote></blockquote><a href="https://en.wikipedia.org/wiki/IEEE_floating_point#Total-ordering_predicate" class="">https://en.wikipedia.org/wiki/IEEE_floating_point#Total-ordering_predicate</a><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">:-)<br class=""><br class=""><br class="">Yes, assuming we want to define identity in terms of the IEEE<br class=""></blockquote></blockquote></blockquote>definition<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">of total ordering.<br class=""><br class=""></blockquote><br class="">I see what you're saying here. That could work. Comparable `===` and<br class="">Equatable `<=>` could do its own thing, and FloatingPoint<br class="">`isTotallyOrdered(below:)` can preserve the IEEE definition of total<br class="">ordering<br class=""><br class=""><br class="">Actually, I was hinting at your argument that `===` true iff `<=>` same<br class="">shouldn’t be a semantic requirement of the protocols.<br class=""><br class="">This is another option, but I don’t think it’s going to fly. It seems<br class="">reasonable to assume that `<=>` will have IEEE semantics. We will trip<br class=""></blockquote></blockquote>a<br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">lot of people up if it doesn’t. That’s a big reason we can’t consider<br class="">changing floating point `==` to define an equivalence relation.<br class=""><br class=""></blockquote><br class="">Actually, here I doubt it. The total ordering isn't exposed as part of<br class=""></blockquote>any<br class=""><blockquote type="cite" class="">comparison operator defined in the IEEE spec. In fact, the total ordering<br class="">wasn't introduced until a (fairly) recent IEEE revision, IIUC. Breaking<br class="">`==` would definitely cause people to jump, but `<=>` needn't be the IEEE<br class="">totalOrder predicate IMO.<br class=""></blockquote><br class="">Wait, I thought we were saying that `<=>` could be IEEE totalOrder, and<br class="">`===` could be like `==` but with well-behaved NaNs, so it's still an<br class="">equivalence relation, thus declaring the signedness of 0 to be<br class="">inessential.<br class=""><br class=""></blockquote><br class="">I was (that was the "=== if but not iff <=>" business above), then I<br class="">thought Matthew was saying something different and agreed with him.<br class=""><br class="">What I thought that Matthew thought was actually very insightful. He didn't<br class="">actually think this, apparently, but: IEEE totalOrder does exactly what it<br class="">says on the tin. But, it is not useful for any generic comparisons or (as<br class="">far as I'm aware) any generic sorting algorithms. I cannot conceive of a<br class="">numeric algorithm or a generic algorithm that relies on two equal floating<br class="">point values being ordered based on their binary representation. We should<br class="">have some way of exposing totalOrder to a user of a BinaryFloatingPoint<br class="">type, but I don't know that it should be the basis for floating point<br class="">*identity* with respect to protocol conformance. It's explicitly *not* what<br class="">IEEE recommends for comparison anyway.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">That makes sense. Perhaps IEEE hasn't actually made a principled</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">decision about which aspects of floating point numbers are essential,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">and we have to do it for them.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Xiaodi is swaying me on this point as well. I am no numerics expert so I don’t know of cases where the difference between -0 and +0 matter and whether the reasons they matter in these cases are applicable to generic code or not. But maybe it is the case that they actually don’t. (Or maybe they are just an artifact of the implementation in which case the difference really shouldn’t matter at all)</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Dave</span></div></blockquote></div><br class=""></body></html>