<div dir="ltr">On Fri, Jul 22, 2016 at 8:46 PM, Matthew Johnson <span dir="ltr"><<a href="mailto:matthew@anandabits.com" target="_blank">matthew@anandabits.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Jul 22, 2016, at 8:43 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr">On Fri, Jul 22, 2016 at 8:42 PM, Jaden Geller <span dir="ltr"><<a href="mailto:jaden.geller@gmail.com" target="_blank">jaden.geller@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span><blockquote type="cite">For floating point, I'd hope that `a === b` if `(a <=> b) == .same` *but not iff*. This is to satisfy IEEE 754: "Comparisons shall ignore the sign of zero (so +0 = −0)".</blockquote><div><br></div></span>I don't see why both `(+0) === (-0)` and `(+0) <=> (-0)` can't return `true` and `.same`, respectively.</div></blockquote><div><br></div><div>IEEE 754 also demands that the total ordering place -0 below +0.</div></div></div></div></div></blockquote><div><br></div></span><div>Is this the proposed total ordering for floats in Swift (sorry, I haven’t followed the details of that)?</div></div></div></blockquote><div><br></div><div>Yes, to the extent I understood the proposal.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div>If so then it appears they must have separate identity and thus `===` would consider the sign value. You would need to use `==` if you want IEEE 754 domain specific comparison.</div></div></div></blockquote><div><br></div><div>That is one answer. It leads to Pyry's surprising result above though.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">This doesn't break the total ordering of values. `===` doesn't do raw memory comparison. They're "identical", so it ought to return `true`.<div><div><br><div><br><blockquote type="cite"><div>On Jul 22, 2016, at 6:37 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Fri, Jul 22, 2016 at 8:20 PM, Dave Abrahams via swift-evolution<span> </span><span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span><span> </span>wrote:<br><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-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span><br>on Fri Jul 22 2016, Daniel Duan <<a href="http://daniel-at-duan.org/" target="_blank">daniel-AT-duan.org</a>> wrote:<br><br>>> On Jul 22, 2016, at 3:00 PM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>>><br>>><br></span><span>>> on Fri Jul 22 2016, Daniel Duan <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><span> </span><mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>> wrote:<br>>><br>><br>>>>> On Jul 22, 2016, at 11:05 AM, Dave Abrahams via swift-evolution<br></span><span>>>>> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><span> </span><mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>> wrote:<br>>>>><br>>>>><br>>>>> on Thu Jul 21 2016, Duan<br>>>><br>>>>> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><span> </span><mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><br></span>>>>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><span> </span><mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>>><br><span>>>>> wrote:<br>>>>><br>>>>>> Great proposal. I want to second that areSame may mislead user to<br>>>>>> think this is about identity.<br>>>>>><br>>>>>> I like areEquivalent() but there may be better names.<br>>>>><br>>>>> It really *is* about identity as I posted in a previous message. But<br>>>>> that doesn't change the fact that areEquivalent might be a better name.<br>>>>> It's one of the things we considered; it just seemed long for no real<br>>>>> benefit.<br>>>>><br>>>><br>>>> If the addresses of the arguments aren’t being used, then we don’t consider<br>>>> them part of their *identity*. I can follow this logic. My fear is most users<br>>>> won’t make this leap on their own and get the same initial impression as I did.<br>>>> It's entirely possible this fear is unfounded. Some educated bikesheding<br>>>> wouldn't hurt here IMO :)<br>>><br>>> Well, it's still a very real question whether we ought to have the<br>>> additional API surface implied by areSame, or wether we should collapse<br>>> it with ===.<br>>><br>><br>> To spell this out (because I had to think about it for a second): === will be derived from<br>> <=>,<br>> but also becomes default implementation for ==, which remains open for<br>> customization.<br><br></span>I was imagining roughly this (untested):<br><br> <span> </span>/// Two references are identical if they refer to the same<br> <span> </span>/// instance.<br> <span> </span>///<br> <span> </span>/// - Note: Classes with a more-refined notion of “identical”<br> <span> </span>/// should conform to `Identifiable` and implement `===`.<br> <span> </span>func ===(lhs: AnyObject, rhs: AnyObject) -> Bool {<br> <span> </span>ObjectIdentifier(lhs) == ObjectIdentifier(rhs)<br> <span> </span>}<br><br> <span> </span>/// Supports testing that two values of `Self` are identical<br> <span> </span>///<br> <span> </span>/// If `a` and `b` are of type `Self`, `a === b` means that<br> <span> </span>/// `a` and `b` are interchangeable in most code. A conforming<br> <span> </span>/// type can document that specific observable characteristics<br> <span> </span>/// (such as the `capacity` of an `Array`) are inessential and<br> <span> </span>/// thus not to be considered as part of the interchangeability<br> <span> </span>/// guarantee.<br> <span> </span>///<br> <span> </span>/// - Requires: `===` induces an equivalence relation over<br> <span> </span>/// instances.<br> <span> </span>/// - Note: conforming types will gain an `==` operator that<br> <span> </span>/// forwards to `===`.<br> <span> </span>/// - Note: Types that require domain-specific `==`<br> <span> </span>/// implementations with different semantics (e.g. floating<br> <span> </span>/// point) should define a more-specific overload of `==`,<br> <span> </span>/// which will be used in contexts where the static type is<br> <span> </span>/// known to the compiler.<br> <span> </span>/// - Note: Generic code should usually use `==` to compare<br> <span> </span>/// conforming instances; that will always dispatch to `===`<br> <span> </span>/// and will be unaffected by more specific overloads of<br> <span> </span>/// `==`.<br> <span> </span>protocol Identifiable { // née Equatable name is negotiable<br> <span> </span>func ===(_: Self, _: aSelf) -> Bool<br> <span> </span>}<br><br> <span> </span>/// Default definition of `==` for Identifiable types.<br> <span> </span>func ==<T: Identifiable>(lhs: T, rhs: T) -> Bool {<br> <span> </span>return lhs === rhs<br> <span> </span>}<br><br> <span> </span>/// Conforming types have a default total ordering.<br> <span> </span>///<br> <span> </span>/// If `a` and `b` are of type `Self`, `a <=> b` means that<br> <span> </span>/// `a` and `b` are interchangeable in most code. A conforming<br> <span> </span>/// type can document that specific observable characteristics<br> <span> </span>/// (such as the `capacity` of an `Array`) are inessential and<br> <span> </span>/// thus not to be considered as part of the interchangeability<br> <span> </span>/// guarantee.<br> <span> </span>///<br> <span> </span>/// - Requires: `<=>` induces a total ordering over<br> <span> </span>/// instances.<br> <span> </span>/// - Requires: the semantics of `<=>` are consistent with<br> <span> </span>/// those of `===`. That is, `(a <=> b) == .equivalent`<br> <span> </span>/// iff `a === b`.<br></blockquote><div><br></div><div>For floating point, I'd hope that `a === b` if `(a <=> b) == .same` *but not iff*. This is to satisfy IEEE 754: "Comparisons shall ignore the sign of zero (so +0 = −0)".</div><div> </div><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> </span>/// - Note: conforming types will gain `<`, `<=`, `>`, and `>=`<br> <span> </span>/// operators defined in terms of `<=>`.<br> <span> </span>/// - Note: Types that require domain-specific `<`, etc.<br> <span> </span>/// implementations with different semantics (e.g. floating<br> <span> </span>/// point) should define more-specific overloads of those<br> <span> </span>/// operators, which will be used in contexts where the<br> <span> </span>/// static type is known to the compiler.<br> <span> </span>/// - Note: Generic code can freely use `<=>` or the traditional<br> <span> </span>/// comparison operators to compare conforming instances;<br> <span> </span>/// the result will always be supplied by `<=>`<br> <span> </span>/// and will be unaffected by more specific overloads of<br> <span> </span>/// the other operators.<br> <span> </span>protocol Comparable : Identifiable {<br> <span> </span>func <=> (lhs: Self, rhs: Self) -> Ordering<br> <span> </span>}<br><br> <span> </span>/// Default implementations of `<`, `<=`, `>`, and `>=`.<br> <span> </span>extension Comparable {<br> <span> </span>static func <(lhs: Self, rhs: Self) -> Bool {<br> <span> </span>return (lhs <=> rhs) == .ascending<br> <span> </span>}<br> <span> </span>static func <=(lhs: Self, rhs: Self) -> Bool {<br> <span> </span>return (rhs <=> lhs) != .ascending<br> <span> </span>}<br> <span> </span>static func >(lhs: Self, rhs: Self) -> Bool {<br> <span> </span>return (lhs <=> rhs) == .descending<br> <span> </span>}<br> <span> </span>static func >=(lhs: Self, rhs: Self) -> Bool {<br> <span> </span>return (rhs <=> lhs) != .descending<br><div><div> <span> </span>}<br> <span> </span>}<br><br>> I like this idea. If we keep === as a separate thing, now users have 3 “opportunities” to define<br>> equality. The must be few, if any, use cases for this.<br>><br>> Would love to see if anyone on the list can give us an example. Otherwise we should make<br>> areSame === again™!<br>><br>>>><br>>>>>> Daniel Duan<br>>>>>> Sent from my iPhone<br>>>>>><br>>>>>>> On Jul 21, 2016, at 6:32 PM, Robert Widmann via swift-evolution<br>>>>>>> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>>>>>>><br>>>>>>><br>>>>>>>> On Jul 21, 2016, at 6:19 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:<br>>>>>>>><br>>>>>>>> This is nice. Is `areSame()` being proposed because static `==` is<br>>>>>>>> the status quo and you're trying to make the point that `==` in the<br>>>>>>>> future need not guarantee the same semantics?<br>>>>>>><br>>>>>>> Yep! Equivalence and equality are strictly very different things.<br>>>>>>><br>>>>>>>><br>>>>>>>> Nit: I think the more common term in stdlib would be<br>>>>>>>> `areEquivalent()`. Do you think `same` in that context (independent<br>>>>>>>> of the word "ordering") might erroneously suggest identity?<br>>>>>>><br>>>>>>> There is room for improvement here. Keep ‘em coming.<br>>>>>>><br>>>>>>>><br>>>>>>>><br>>>>>>>>> On Thu, Jul 21, 2016 at 8:11 PM, Robert Widmann via<br>>>>>>>>> swift-evolution<br>>>>>>>>> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>>>>>>>>> Hello Swift Community,<br>>>>>>>>><br>>>>>>>>> Harlan Haskins, Jaden Geller, and I have been working on a<br>>>>>>>>> proposal to clean up the semantics of ordering relations in the<br>>>>>>>>> standard library. We have a draft that you can get as a gist.<br>>>>>>>>> Any feedback you might have about this proposal helps - though<br>>>>>>>>> please keeps your comments on Swift-Evolution and not on the gist.<br>>>>>>>>><br>>>>>>>>> Cheers,<br>>>>>>>>><br>>>>>>>>> ~Robert Widmann<br>>>>>>>>><br>>>>>>>>><br>>>>>>>>><br>>>>>>>>><br>>>>>>>>><br>>>>>>>>> _______________________________________________<br>>>>>>>>> swift-evolution mailing list<br>>>>>>>>><span> </span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>>>>>>>>><span> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>>>>>>>>><br>>>>>>>><br>>>>>>><br>>>>>>> _______________________________________________<br>>>>>>> swift-evolution mailing list<br>>>>>>><span> </span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>>>>>>><span> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>>>>>> _______________________________________________<br>>>>>> swift-evolution mailing list<br>>>>>><span> </span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>>>>>><span> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>>>>>><br>>>>><br>>>>> --<br>>>>> Dave<br>>>>><br>>>>> _______________________________________________<br>>>>> swift-evolution mailing list<br>>>>><span> </span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div></div>>>>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><span> </span><mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>><br><span>>>>><span> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</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>>>>> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</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>>>> _______________________________________________<br>>>> swift-evolution mailing list<br></span>>>><span> </span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><span> </span><mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><br><span>>>><span> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</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>>>><br>>><br>>> --<br>>> Dave<br>>><br>>> _______________________________________________<br>>> swift-evolution mailing list<br>>><span> </span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><span> </span><mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><br>>><span> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</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><br></span><div><div>--<br>Dave<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></div></div></blockquote></div><br></div></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br></div></div></div></blockquote></div><br></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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>