<div dir="ltr">On Fri, Jul 22, 2016 at 8:20 PM, Dave Abrahams via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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 class="gmail-"><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 <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>><br>
>><br>
</span><span class="gmail-">>> on Fri Jul 22 2016, Daniel Duan <<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 Jul 22, 2016, at 11:05 AM, Dave Abrahams via swift-evolution<br>
</span><span class="gmail-">>>>> <<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>
</span>>>>> <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>
<span class="gmail-">>>>> 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>
/// 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></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">
/// - 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>
<div><div class="gmail-h5"> }<br>
}<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">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>> 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>
</div></div>>>>> <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>
<span class="gmail-">>>>> <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>>>> <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>
<span class="gmail-im gmail-HOEnZb">>>> <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>
</span><div class="gmail-HOEnZb"><div class="gmail-h5">--<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>
</div></div></blockquote></div><br></div></div>