<div dir="ltr"><br style="font-size:14px"><span style="font-size:14px">func add2(_ pair: (Int, Int)) -> Int {</span><br style="font-size:14px"><span style="font-size:14px"> return pair.0 + pair.1</span><br style="font-size:14px"><span style="font-size:14px">}</span><br><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">consider the follows</span></div><div><br></div><span style="font-size:14px">let _add2 = </span><span style="font-size:14px">add2 // </span><span style="font-size:14px">add2 have the typeof `((Int, Int)) -> Int`, it should flatten to </span><span style="font-size:14px">`(Int, Int) -> Int`</span><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">so these two lines are also acceptable</span></div><div><span style="font-size:14px">[(1, 2)].map(add1)</span><br style="font-size:14px"><span style="font-size:14px">[(1, 2)].map(add2)</span><span style="font-size:14px"><br></span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">this proposal is not just changing the behaviour of closure, this proposal also changing the tuple type</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">(((Int, Int))) flatten to (Int, Int)</span></div><div><span style="font-size:14px">(Int, </span><span style="font-size:14px">(((Int, Int))), Int</span><span style="font-size:14px">)</span><span style="font-size:14px"> flatten to </span><span style="font-size:14px">(Int, </span><span style="font-size:14px">(Int, Int)</span><span style="font-size:14px">, Int)</span></div><div><span style="font-size:14px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-07 12:03 GMT+08:00 Stephen Celis <span dir="ltr"><<a href="mailto:stephen.celis@gmail.com" target="_blank">stephen.celis@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The inline cases make sense to me, but my concern for ambiguity are because we can define both of these functions:<br>
<br>
func add1(_ x: Int, _ y: Int) -> Int {<br>
return x + y<br>
}<br>
func add2(_ pair: (Int, Int)) -> Int {<br>
return pair.0 + pair.1<br>
}<br>
<br>
// What's the behavior here?<br>
[(1, 2)].map(add1)<br>
[(1, 2)].map(add2)<br>
<br>
What comes to mind, though, is, Swift already prevents single-element tuples, so why not prevent functions that take a single tuple as the only argument?<br>
<br>
Swift could provide a fix-it for functions that take single tuples and say: "Swift functions cannot take a single tuple. Please write a function that takes as many arguments as the tuple specified."<br>
<br>
Considering the fact that Swift generally operates in a multi-argument world, and given that functions taking a single tuple are the minority, I think this would be a good way to move forward.<br>
<span class="HOEnZb"><font color="#888888"><br>
Stephen<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Jun 6, 2017, at 11:21 PM, Susan Cheng <<a href="mailto:susan.doggie@gmail.com">susan.doggie@gmail.com</a>> wrote:<br>
><br>
> [(1, 2)].map({ x, y in x + y }) // this line is correct<br>
> [(1, 2)].map({ tuple in tuple.0 + tuple.1 }) // this line should not accepted<br>
><br>
> or<br>
><br>
> [(1, 2)].map({ $0 + $1 }) // this line is correct<br>
> [(1, 2)].map({ $0.0 + $0.1 }) // this line should not accepted<br>
><br>
> it's because `((Int, Int)) -> Int` always flatten to `(Int, Int) -> Int`<br>
> so, it should only accept the function with two arguments<br>
><br>
><br>
><br>
> 2017-06-07 11:07 GMT+08:00 Stephen Celis <<a href="mailto:stephen.celis@gmail.com">stephen.celis@gmail.com</a>>:<br>
> I like this a lot, but how do we solve for the function case?<br>
><br>
> func add(_ x: Int, _ y: Int) -> Int {<br>
> return x + y<br>
> }<br>
> [(1, 2)].map(add)<br>
><br>
> Where does `map` with a function of `((Int, Int)) -> Int` fit in?<br>
><br>
> > On Jun 6, 2017, at 10:15 PM, Susan Cheng via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
> ><br>
> > Introduction<br>
> ><br>
> ><br>
> > Because the painful of SE-0110, here is a proposal to clarify the tuple syntax.<br>
> ><br>
> > Proposed solution<br>
> ><br>
> > 1. single element tuple always be flattened<br>
> ><br>
> > let tuple1: (((Int))) = 0 // TypeOf(tuple1) == Int<br>
> ><br>
> > let tuple2: ((((Int))), Int) = (0, 0) // TypeOf(tuple2) == (Int, Int)<br>
> ><br>
> > 2. function arguments list also consider as a tuple, which means the function that accept a single tuple should always be flattened.<br>
> ><br>
> > let fn1: (Int, Int) -> Void = { _, _ in }<br>
> ><br>
> > let fn2: ((Int, Int)) -> Void = { _, _ in } // always flattened<br>
> ><br>
> > let fn3: (Int, Int) -> Void = { _ in } // not allowed, here are two arguments<br>
> ><br>
> > let fn4: ((Int, Int)) -> Void = { _ in } // not allowed, here are two arguments<br>
> ><br>
> > ______________________________<wbr>_________________<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/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>