[swift-evolution] Proposal: Always flatten the single element tuple

Xiaodi Wu xiaodi.wu at gmail.com
Wed Jun 7 22:36:48 CDT 2017


On Wed, Jun 7, 2017 at 10:15 PM, Susan Cheng via swift-evolution <
swift-evolution at swift.org> wrote:

> Just a thought
>
> if parentheses is important, why the tuples are not?
>

It is not parentheses that are important; it is the distinction between an
argument list and a tuple. They both happen to be written with parentheses.

var tuple1: (Int, Int) = (0, 0)
>
> var tuple2: ((((Int, Int)))) = (0, 0)
>
>
> type(of: tuple1) == type(of: tuple2)    // true
>
>
> var void: ((((((())))))) = ()
>
>
> type(of: void) == type(of: Void())  // true
>
>
> 2017-06-07 10:15 GMT+08:00 Susan Cheng <susan.doggie at gmail.com>:
>
>> Introduction
>>
>> Because the painful of SE-0110, here is a proposal to clarify the tuple
>> syntax.
>>
>> Proposed solution
>> 1. single element tuple always be flattened
>>
>> let tuple1: (((Int))) = 0  // TypeOf(tuple1) == Int
>>
>>
>> let tuple2: ((((Int))), Int) = (0, 0)  // TypeOf(tuple2) == (Int, Int)
>>
>> 2. function arguments list also consider as a tuple, which means the
>> function that accept a single tuple should always be flattened.
>>
>> let fn1: (Int, Int) -> Void = { _, _ in }
>>
>>
>> let fn2: ((Int, Int)) -> Void = { _, _ in }  // always flattened
>>
>> let fn3: (Int, Int) -> Void = { _ in }  // not allowed, here are two
>> arguments
>>
>> let fn4: ((Int, Int)) -> Void = { _ in }  // not allowed, here are two
>> arguments
>>
>>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170607/a441ffe4/attachment.html>


More information about the swift-evolution mailing list