[swift-evolution] Revisiting SE-0110

Vladimir.S svabox at gmail.com
Mon May 29 12:32:44 CDT 2017


On 29.05.2017 18:26, Nevin Brackett-Rozinsky via swift-evolution wrote:
> On Sun, May 28, 2017 at 7:04 PM, John McCall via swift-evolution 
> <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> 
>     We need to add back tuple destructuring in closure parameter lists because this
>     is a serious usability regression.  If we're reluctant to just "do the right
>     thing" to handle the ambiguity of (a,b), we should at least allow it via
>     unambiguous syntax like ((a,b)).  I do think that we should just "do the right
>     thing", however, with my biggest concern being whether there's any reasonable way
>     to achieve that in 4.0.
> 
>     John.
> 
> 
> I agree with John, the best thing for actually using Swift is to allow tuple 
> destructuring here, and the outermost parentheses (around the entire parameter list 
> of a closure) should continue to be optional. Requiring double-parens would seem 
> unnecessarily and arbitrarily…whatever the opposite of “convenient” is.
> 
> Nevin

If I understand correctly, correct me if I'm wrong, after *full* implementation of 
SE-0066, the function with two parameters should have different type than function 
with one tuple parameter:

I.e.
typealias FuncParams = (Int, Int)->()
typealias FuncTuple = ((Int, Int))->()

print(FuncParams.self) // should be (Int, Int)->()
print(FuncTuple.self) // should be ((Int, Int))->()

So, if we have

func barParams(_ f: FuncParams) {
	f(1,2)
}

func barTuple(_ f: FuncTuple) {
	f((1,2))
}

and

func fooWithParams(_ x: Int,  _ y: Int) {  }
func fooWithTuple(_ tuple: (Int, Int)) {  }

.. we should not be able to call

barParams(fooWithTuple) // should be error: incompatible types
barTuple(fooWithParams) // should be error: incompatible types


If so, are you suggesting that this code should still be valid?

barParams({tuple in}) // ?
barTuple({x,y in}) // ?


Will {x,y in} closure has ((Int, Int))->() type in this case?
And if {tuple in} should be of type (Int,Int)->() ?

If I'm not missing something, the only reasonable solution here is follow the SE-0066 
rules for function types and allow special syntax ((x,y)) to deconstruct tuple parts 
in closure argument list, and such closure will have type ((Int,Int))->() as 
expected. So we'll have:

barTuple({((x,y)) in ... })


> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
> 


More information about the swift-evolution mailing list