[swift-evolution] Synthesizing Equatable, Hashable, and Comparable for tuple types
Xiaodi Wu
xiaodi.wu at gmail.com
Sat Nov 25 17:07:28 CST 2017
On Sat, Nov 25, 2017 at 16:44 Mike Kluev <mike.kluev at gmail.com> wrote:
> On 25 November 2017 at 22:38, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
>> On Sat, Nov 25, 2017 at 4:30 PM, Mike Kluev <mike.kluev at gmail.com> wrote:
>>
>>>
>>>> i haven't encounter this notation before so it looks strange and
>>> requires some effort to decipher. if it was e.g. in this form:
>>>
>>> extension (Equatable...) : Equatable
>>>
>>> then it would be immediately obvious what it means, IMHO
>>>
>>
>> That reads to me like you are extending a tuple of type `(Equatable...)`.
>> This is not the same as extending a tuple of type `(E...) where ...E :
>> Equatable`.
>>
>
> and if Equatable is not a type but a protocol then the practical
> difference is what ?
>
Not sure what you’re asking. Equatable is a protocol.
For a protocol P, (P, P) is a concrete type with two elements each of
existential type P. For a type T : P, a tuple of type (T, T) is not a tuple
of type (P, P). If we can extend tuples, you can write a generic algorithm
that works with any type (T, T) where T : P, and/or you can write an
algorithm that works with concrete type (P, P). Note that there is no
overlap between these two because existential type P does not conform to
protocol P.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171125/052f050f/attachment.html>
More information about the swift-evolution
mailing list