<div dir="ltr">On Fri, Jul 22, 2016 at 8:45 PM, Dave Abrahams <span dir="ltr"><<a href="mailto:dabrahams@apple.com" target="_blank">dabrahams@apple.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 class="HOEnZb"><div class="h5"><br>
on Fri Jul 22 2016, Xiaodi Wu <<a href="http://xiaodi.wu-AT-gmail.com" rel="noreferrer" target="_blank">xiaodi.wu-AT-gmail.com</a>> wrote:<br>
<br>
> On Fri, Jul 22, 2016 at 8:20 PM, Dave Abrahams via swift-evolution <<br>
> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
>><br>
>> on Fri Jul 22 2016, Daniel Duan <daniel-AT-duan.org> wrote:<br>
>><br>
>> >> On Jul 22, 2016, at 3:00 PM, Dave Abrahams via swift-evolution <<br>
>> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>> >><br>
>> >><br>
>> >> on Fri Jul 22 2016, Daniel Duan <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <mailto:<br>
>> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>> wrote:<br>
>> >><br>
>> ><br>
>> >>>> On Jul 22, 2016, at 11:05 AM, Dave Abrahams via swift-evolution<br>
>> >>>> <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>> wrote:<br>
>> >>>><br>
>> >>>><br>
>> >>>> on Thu Jul 21 2016, Duan<br>
>> >>><br>
>> >>>> <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>><br>
>> >>>> <mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
>> >>><br>
>> >>>> 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<br>
>> 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<br>
>> consider<br>
>> >>> them part of their *identity*. I can follow this logic. My fear is<br>
>> most users<br>
>> >>> won’t make this leap on their own and get the same initial impression<br>
>> as I did.<br>
>> >>> It's entirely possible this fear is unfounded. Some educated<br>
>> 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): ===<br>
>> will be derived from<br>
>> > <=>,<br>
>> > but also becomes default implementation for ==, which remains open for<br>
>> > customization.<br>
>><br>
>> I was imagining roughly this (untested):<br>
>><br>
>> /// Two references are identical if they refer to the same<br>
>> /// instance.<br>
>> ///<br>
>> /// - Note: Classes with a more-refined notion of “identical”<br>
>> /// should conform to `Identifiable` and implement `===`.<br>
>> func ===(lhs: AnyObject, rhs: AnyObject) -> Bool {<br>
>> ObjectIdentifier(lhs) == ObjectIdentifier(rhs)<br>
>> }<br>
>><br>
>> /// Supports testing that two values of `Self` are identical<br>
>> ///<br>
>> /// If `a` and `b` are of type `Self`, `a === b` means that<br>
>> /// `a` and `b` are interchangeable in most code. A conforming<br>
>> /// type can document that specific observable characteristics<br>
>> /// (such as the `capacity` of an `Array`) are inessential and<br>
>> /// thus not to be considered as part of the interchangeability<br>
>> /// guarantee.<br>
>> ///<br>
>> /// - Requires: `===` induces an equivalence relation over<br>
>> /// instances.<br>
>> /// - Note: conforming types will gain an `==` operator that<br>
>> /// forwards to `===`.<br>
>> /// - Note: Types that require domain-specific `==`<br>
>> /// implementations with different semantics (e.g. floating<br>
>> /// point) should define a more-specific overload of `==`,<br>
>> /// which will be used in contexts where the static type is<br>
>> /// known to the compiler.<br>
>> /// - Note: Generic code should usually use `==` to compare<br>
>> /// conforming instances; that will always dispatch to `===`<br>
>> /// and will be unaffected by more specific overloads of<br>
>> /// `==`.<br>
>> protocol Identifiable { // née Equatable name is negotiable<br>
>> func ===(_: Self, _: aSelf) -> Bool<br>
>> }<br>
>><br>
>> /// Default definition of `==` for Identifiable types.<br>
>> func ==<T: Identifiable>(lhs: T, rhs: T) -> Bool {<br>
>> return lhs === rhs<br>
>> }<br>
>><br>
>> /// Conforming types have a default total ordering.<br>
>> ///<br>
>> /// If `a` and `b` are of type `Self`, `a <=> b` means that<br>
>> /// `a` and `b` are interchangeable in most code. A conforming<br>
>> /// type can document that specific observable characteristics<br>
>> /// (such as the `capacity` of an `Array`) are inessential and<br>
>> /// thus not to be considered as part of the interchangeability<br>
>> /// guarantee.<br>
>> ///<br>
>> /// - Requires: `<=>` induces a total ordering over<br>
>> /// instances.<br>
>> /// - Requires: the semantics of `<=>` are consistent with<br>
>> /// those of `===`. That is, `(a <=> b) == .equivalent`<br>
>> /// iff `a === b`.<br>
>><br>
><br>
> For floating point, I'd hope that `a === b` if `(a <=> b) == .same` *but<br>
> not iff*. This is to satisfy IEEE 754: "Comparisons shall ignore the sign<br>
> of zero (so +0 = −0)".<br>
<br>
</div></div>By “comparisons” they mean the traditional comparison operators, not all<br>
possible comparisons you might want to do.<br></blockquote><div><br></div><div>I don't believe so, but I could be corrected by Steve. They list 26 comparison relations and don't go into what they call `=` until later, so I take than as an example.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
That single equal sign in their text corresponds to == in the world<br>
being proposed, so that's fine.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
><br>
>> /// - Note: conforming types will gain `<`, `<=`, `>`, and `>=`<br>
>> /// operators defined in terms of `<=>`.<br>
>> /// - Note: Types that require domain-specific `<`, etc.<br>
>> /// implementations with different semantics (e.g. floating<br>
>> /// point) should define more-specific overloads of those<br>
>> /// operators, which will be used in contexts where the<br>
>> /// static type is known to the compiler.<br>
>> /// - Note: Generic code can freely use `<=>` or the traditional<br>
>> /// comparison operators to compare conforming instances;<br>
>> /// the result will always be supplied by `<=>`<br>
>> /// and will be unaffected by more specific overloads of<br>
>> /// the other operators.<br>
>> protocol Comparable : Identifiable {<br>
>> func <=> (lhs: Self, rhs: Self) -> Ordering<br>
>> }<br>
>><br>
>> /// Default implementations of `<`, `<=`, `>`, and `>=`.<br>
>> extension Comparable {<br>
>> static func <(lhs: Self, rhs: Self) -> Bool {<br>
>> return (lhs <=> rhs) == .ascending<br>
>> }<br>
>> static func <=(lhs: Self, rhs: Self) -> Bool {<br>
>> return (rhs <=> lhs) != .ascending<br>
>> }<br>
>> static func >(lhs: Self, rhs: Self) -> Bool {<br>
>> return (lhs <=> rhs) == .descending<br>
>> }<br>
>> static func >=(lhs: Self, rhs: Self) -> Bool {<br>
>> return (rhs <=> lhs) != .descending<br>
>> }<br>
>> }<br>
>><br>
>> > I like this idea. If we keep === as a separate thing, now users have 3<br>
>> “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.<br>
>> 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">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">xiaodi.wu@gmail.com</a>><br>
>> 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">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>
>> >>>>>>>> <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>
>> >>>>>>>><br>
>> >>>>>>><br>
>> >>>>>><br>
>> >>>>>> _______________________________________________<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>
>> >>>>> _______________________________________________<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>
>> >>>>><br>
>> >>>><br>
>> >>>> --<br>
>> >>>> Dave<br>
>> >>>><br>
>> >>>> _______________________________________________<br>
>> >>>> swift-evolution mailing list<br>
>> >>>> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
>> >>>> <mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <mailto:<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>
>> >>>> <<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>
>> >>> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <mailto:<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>
>> >>> <<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>
>> >> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <mailto:<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>
>> >> <<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>
>> Dave<br>
>> _______________________________________________<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>
>><br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Dave<br>
</font></span></blockquote></div><br></div></div>