<div dir="ltr">Slava Pestov answered this question on Twitter.<div>He says it's a known bug and: "Right now, function types always have a single parameter internally. Diff between a and b is lost after type check".</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 27, 2016 at 6:28 PM, Jens Persson <span dir="ltr"><<a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>IMHO Swift's handling of function types violate the principle of least surprise.</div><div><br></div><div>In the example program below, are `a` and `b` really of the same function type?</div><div><br></div><div>I searched but couldn't find any proposal or discussion addressing this.</div><div><br></div><div><br></div><div>// (Xcode 8 beta 6, toolchain: development snapshot 2016-08-26)</div><div><br></div><div>let a: (Int, Int) -> Int = { (a, b) in a + b }</div><div>let b: ((Int, Int)) -> Int = a</div><div>// So `a` can be casted to `b`'s type, OK.</div><div><br></div><div>print(type(of:a)) // ((Int, Int)) -> Int</div><div>print(type(of:b)) // ((Int, Int)) -> Int</div><div><br></div><div>// Why are they printed the same?</div><div>// I would only expect `b`'s type to look like that.</div><div>// Now it looks like both take a tuple of two Ints.</div><div><br></div><div>let c = a( 1, 2 ) // Can only be called this way, as expected.</div><div>let d = b((1, 2)) // Can only be called this way, as expected.</div><div>print(c) // 3, as expected.</div><div>print(d) // 3, as expected.</div><div><br></div><div>print(type(of:a) == type(of:b)) // true</div><div>// What? `a` clearly takes two Ints, while `b` clearly takes a</div><div>// tuple of two Ints, yet they are the same type?</div><div>// I am perplexed.</div><div><br></div></div>
</blockquote></div><br></div>