<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 14 Jul 2016, at 05:47, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md</a></div><br class="">Shortly after SE-0111 was accepted last week, several people newly noticed the proposal and started a discussion about how it appears to be a regression for closure parameters (e.g. callbacks) that could formerly carry labels, but are now not allowed to. &nbsp;These folks observed that it would be more expressive (and consistent with the rest of Swift) to allow parameter labels in function types, because the invocation site of a closure “should" be required to provide those labels. &nbsp;The core team has been following the discussion, agrees that this is a concern, and wants to update the community with a path forward.<div class=""><br class=""></div><div class="">The reality of the situation is that the current implementation of parameter labels in function types is inherently broken. &nbsp;Specifically, as one example, there is an implicit conversion from "<font face="Menlo" class="">(a: Int) -&gt; Int</font>” to “<font face="Menlo" class="">(Int) -&gt; Int</font>”. &nbsp;However, there is also an implicit conversion from "<font face="Menlo" class="">(Int) -&gt; Int</font>” to “<font face="Menlo" class="">(b : Int) -&gt; Int</font>”. &nbsp;This means that the compiler currently allows converting from “<font face="Menlo" class="">(a: Int) -&gt; Int</font>” to “<font face="Menlo" class="">(b: Int) -&gt; Int</font>”, which doesn’t make sense, introduces surprising behavior, introduces complexity into the compiler implementation, and is generally a problem. &nbsp;We do have one specific hack to prevent conversion of (e.g.) “<font face="Menlo" class="">(a : Int, b : Int) -&gt; Void</font>” to “<font face="Menlo" class="">(b : Int, a : Int) -&gt; Void</font>”, but this only triggers in specific cases. &nbsp;There are other more complex cases as well, e.g. when using generics "<font face="Menlo" class="">T&lt;(a : Int)-&gt;Int&gt;</font>” cannot be considered compatible with "<font face="Menlo" class="">T&lt;(b : Int)-&gt;Int&gt;</font>”.</div><div class=""><br class=""></div><div class="">These problems are what initially motivated SE-0111. &nbsp;However, given the feedback, the core team went back to the drawing board to determine whether: a) SE-0111 by itself is the right long term answer, b) whether there were alternate models that could solve the same problems in a different way, or c) whether SE-0111 was the right first step to "ultimate glory" in the field of closure parameter labels. &nbsp;After a long discussion, and many alternatives considered, the core team believes in c), that SE-0111 (with a minor modification) is the right step for Swift 3, because it paves the way for the right model over the long term.</div><div class=""><br class=""></div><div class="">----8&lt;----</div><div class=""><br class=""></div><div class="">The specific revision requested by the core team to SE-0111 is that all “cosmetic” labels should be required to include an API name of _. &nbsp;For example, this would not be allowed:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;var op : (lhs : Int, rhs : Int) -&gt; Int</font></div><div class=""><br class=""></div><div class="">instead, it should be spelled as:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">&nbsp; &nbsp;var op : (_ lhs : Int, _ rhs : Int) -&gt; Int</font></div></div><div class=""><br class=""></div><div class="">With this change, we believe that we have paved the way for a purely additive proposal (and thus, post-Swift 3) that will restore the expressive capability of closures with parameter labels. &nbsp;</div><div class=""><br class=""></div><div class=""><div class=""><div class="">----8&lt;----</div></div></div><div class=""><br class=""></div><div class="">Here is a sketch of how that would work, in two steps:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">First, we extend declaration names for variables, properties, and parameters to allow *parameter names* as part of their declaration name. &nbsp;For example:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;var op(lhs:,rhs:) : (Int, Int) -&gt; Int &nbsp; &nbsp;// variable or property.</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;x = op(lhs: 1, rhs: 2) &nbsp; &nbsp; &nbsp; // use of the variable or property.</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;// API name of parameter is&nbsp;“opToUse”, internal name is "op(lhs:,rhs:)”.</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;func foo(opToUse &nbsp;op(lhs:,rhs:) : (Int, Int) -&gt; Int) {</font></div><div class=""><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp;x = op(lhs: 1, rhs: 2) &nbsp; &nbsp; // use of the parameter</font></div></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;}</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;foo(opToUse: +) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // call of the function</font></div><div class=""><br class=""></div><div class="">This will restore the ability to express the idea of a closure parameter that carries labels as part of its declaration, without requiring parameter labels to be part of the type system (allowing, e.g. the operator + to be passed into something that requires parameter labels).</div></div></div></blockquote><div><br class=""></div><div><div>During the review, Michael Ilseman suggested using SE-0021 for declaration names.</div><div><br class=""></div><div>&lt;<a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/22488/focus=22580" class="">http://thread.gmane.org/gmane.comp.lang.swift.evolution/22488/focus=22580</a>&gt;</div><div><br class=""></div><div>Your example <font face="Menlo" class="">"op(lhs:,rhs:)"</font> would be <font face="Menlo" class="">"op(lhs:rhs:)"</font> instead (i.e. without the comma).</div><div><br class=""></div><div>-- Ben</div></div><br class=""><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Second, extend the rules for function types to allow parameter API labels *if and only if* they are used as the type of a declaration that allows parameter labels, and interpret them as a sugar form for providing those labels on the underlying declaration. &nbsp;This means that the example above could be spelled as:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">&nbsp; &nbsp;var op : (lhs: Int, rhs: Int) -&gt; Int &nbsp; &nbsp;// Nice declaration syntax</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;x = op(lhs: 1, rhs: 2) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Same as above</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;// API name of parameter is&nbsp;“opToUse”, internal name is "op(lhs:,rhs:)”.</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;func foo(opToUse op : (lhs: Int, rhs: Int) -&gt; Int) {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp;x = op(lhs: 1, rhs: 2) &nbsp; &nbsp; // Same as above.</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;}</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;foo(opToUse: +) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//&nbsp;</font><span style="font-family: Menlo;" class="">Same as above.</span></div></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><br class=""></div><div class="">These two steps will provide the simple and expressive design approach that we have now, without all of the problems that representing parameter labels in the type system introduces. &nbsp;The core team believes that the temporary regression in expressiveness is an acceptable loss for Swift 3, particularly given that this will have no impact on Cocoa or the standard library. &nbsp;In the case of Cocoa, recall that C and Objective-C don’t have parameter labels on their corresponding concepts (Blocks and C function pointers), and the higher order functions in the standard library should not require parameter labels either.</div><div class=""><br class=""></div><div class="">-Chris &amp; the Core Team</div></div></blockquote></div></body></html>