[swift-evolution] [Proposal][Discussion] Deprecate Tuple Shuffles

Xiaodi Wu xiaodi.wu at gmail.com
Fri May 5 01:03:33 CDT 2017


On Fri, May 5, 2017 at 1:00 AM, Adrian Zubarev <
adrian.zubarev at devandartist.com> wrote:

> Just to double check, here is the updated version of my code snippet on
> how it would look like if this proposal will be accepted.
>
> let a: (x: Int, y: Int) = (1, 2)
> var b: (y: Int, x: Int) = a
>
> This would be banned. It involves reordering arguments.


> Label swap while destructuring:
>
> let tuple: (first: Int, second: (x: Int, y: Int)) = (0, (1, 2))
>
> let (first: a, second: (x: b, y: c)): (first: Int, second: (x: Int, y: Int)) = tuple // fine, unaffected
>
> This would be banned. You are using labels (things ending with a colon) in
a pattern (the stuff that comes after the word "let").

let (second: (x: b, y: c), first: a): (second: (x: Int, y: Int),
first: Int) = tuple // will the rendering be banned or not?
>
> This would also be banned.


>  Is this correct now?
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> Am 5. Mai 2017 um 07:53:51, Xiaodi Wu (xiaodi.wu at gmail.com) schrieb:
>
> On Fri, May 5, 2017 at 12:52 AM, Adrian Zubarev <
> adrian.zubarev at devandartist.com> wrote:
>
>> Eliminating all labels would mean that even the first example from my
>> last post will be banned.
>>
> No, not eliminating all labels from tuples, but from tuple _patterns_.
>
>
>> Is there any difference from labels in tuple types and labels in tuples
>> themselves?
>>
>> Personally I would not support the removal of labels from tuple types,
>> because it’s a very useful feature that replaces indexed access like
>> myTuple.1 to a more readable counterpart myTuple.somethingSpecial.
>>
>> Am I still missing something out?
>>
>>
>> --
>> Adrian Zubarev
>> Sent with Airmail
>>
>> Am 5. Mai 2017 um 07:43:49, Xiaodi Wu (xiaodi.wu at gmail.com) schrieb:
>>
>> On Fri, May 5, 2017 at 12:42 AM, Adrian Zubarev via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>>> Okay now I see where this is going. So basically you want to mirror the
>>> behavior of function parameters into tuples.
>>>
>>> You might want to be a little bit more explicit on types in your
>>> proposal to better understand the so called ‘tuple shuffle’.
>>>
>>> let a: (x: Int, y: Int) = (x: 1, y: 2)
>>> var b: (y: Int, x: Int) = a
>>> a.x == b.x
>>> a.y == b.y
>>>
>>> Label swap (tuple shuffle) while destructuring:
>>>
>>> let tuple: (first: Int, second: (x: Int, y: Int)) = (first: 0, second: (x: 1, y: 2))
>>>
>>> let (first: a, second: (x: b, y: c)): (first: Int, second: (x: Int, y: Int)) = tuple // fine, unaffected
>>>
>>> let (second: (x: b, y: c), first: a): (second: (x: Int, y: Int), first: Int) = tuple // shuffle => error
>>>
>>>
>> No, I thought this was what Robert was proposing, but he is proposing the
>> elimination of all labels in tuple patterns. Your second example would be
>> banned.
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170505/7cd15d33/attachment.html>


More information about the swift-evolution mailing list