<div dir="ltr"><div>Here is the message I was talking about: <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160711/024331.html">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160711/024331.html</a><br><br></div>Message quoted here for your convenience:<br><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><pre><i>Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md">https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md</a>

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.  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&quot; be required to provide those labels.  The core team has been following the discussion, agrees that this is a concern, and wants to update the community with a path forward.

The reality of the situation is that the current implementation of parameter labels in function types is inherently broken.  Specifically, as one example, there is an implicit conversion from &quot;(a: Int) -&gt; Int” to “(Int) -&gt; Int”.  However, there is also an implicit conversion from &quot;(Int) -&gt; Int” to “(b : Int) -&gt; Int”.  This means that the compiler currently allows converting from “(a: Int) -&gt; Int” to “(b: Int) -&gt; Int”, which doesn’t make sense, introduces surprising behavior, introduces complexity into the compiler implementation, and is generally a problem.  We do have one specific hack to prevent conversion of (e.g.) “(a : Int, b : Int) -&gt; Void” to “(b : Int, a : Int) -&gt; Void”, but this only triggers in specific cases.  There are other more complex cases as well, e.g. when using generics &quot;T&lt;(a : Int)-&gt;Int&gt;” cannot be considered compatible with &quot;T&lt;(b : Int)-&gt;Int&gt;”.

These problems are what initially motivated SE-0111.  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 &quot;ultimate glory&quot; in the field of closure parameter labels.  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.

----8&lt;----

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 _.  For example, this would not be allowed:

   var op : (lhs : Int, rhs : Int) -&gt; Int

instead, it should be spelled as:

   var op : (_ lhs : Int, _ rhs : Int) -&gt; Int

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.  

----8&lt;----

Here is a sketch of how that would work, in two steps:


First, we extend declaration names for variables, properties, and parameters to allow *parameter names* as part of their declaration name.  For example:

   var op(lhs:,rhs:) : (Int, Int) -&gt; Int    // variable or property.
   x = op(lhs: 1, rhs: 2)       // use of the variable or property.

   // API name of parameter is “opToUse”, internal name is &quot;op(lhs:,rhs:)”.
   func foo(opToUse  op(lhs:,rhs:) : (Int, Int) -&gt; Int) {
     x = op(lhs: 1, rhs: 2)     // use of the parameter
   }
   foo(opToUse: +)             // call of the function

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).


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.  This means that the example above could be spelled as:

   var op : (lhs: Int, rhs: Int) -&gt; Int    // Nice declaration syntax
   x = op(lhs: 1, rhs: 2)                  // Same as above

   // API name of parameter is “opToUse”, internal name is &quot;op(lhs:,rhs:)”.
   func foo(opToUse op : (lhs: Int, rhs: Int) -&gt; Int) {
     x = op(lhs: 1, rhs: 2)     // Same as above.
   }
   foo(opToUse: +)              // Same as above.


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.  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.  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.

-Chris &amp; the Core Team</i></pre></blockquote></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 4, 2016 at 10:27 PM, T.J. Usiyan via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I noticed this immediately and assumed that it was recognized as suboptimal but tolerable for now. The required underscores were meant to leave space for improvement in this regard, no? If not… sad face.<div><br></div><div>TJ</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Oct 4, 2016 at 12:21 PM, Erica Sadun via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div style="word-wrap:break-word">SE-0111 established that Swift&#39;s type system would not allow function argument labels to be expressed as part of a function type. As I&#39;ve been working with curried functions, I&#39;m discovering an unintended consequence of this proposal in that it strips curried functions of their external labels and the resulting calls of their readability.<div><br></div><div>```</div><div><div><font face="Menlo">public func projected(</font></div><div><font face="Menlo">    function f: @escaping (CGFloat) -&gt; CGFloat) -&gt;</font></div><div><font face="Menlo">    (_ p0: CGPoint, _ p1: CGPoint) -&gt; </font></div><div><font face="Menlo">    (_ percent: CGFloat) -&gt; CGPoint</font></div><div><font face="Menlo">{</font></div></div><div>```</div><div><br></div><div>Calling the first level of currying still reads acceptably:</div><div><br></div><div>```</div><div><font face="Menlo">let projectedFunction = projected(function: fToApply)</font></div><div>```</div><div><br></div><div>But after that, the enforced label-less arguments mean all further semantics have to stay within the name of the assigned partially applied function symbol and all arguments must be supplied without meaning, which is not in the spirit of API guidelines or under the umbrella of Swiftiness:</div><div><br></div><div>```</div><div><font face="Menlo">let fixedFunction = projectedFunction(p0, p1)</font></div><div><font face="Menlo">let value = fixedFunction(0.2)</font></div><div>```</div><div><br></div><div>There&#39;s no way to give either the line segment start and end points or the percent-of-progress arguments any labels.  Further, Xcode/QuickHelp does not provide any support for documenting the roles of each curried return type.</div><div><br></div><div>Could this be addressed specifically for currying or has the boat sailed forever on this topic?</div><span class="m_8666887673830996894HOEnZb"><font color="#888888"><div><br></div><div>-- E</div><div><br></div></font></span></div><br></div></div><span class="">______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></span></blockquote></div><br></div>
<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></blockquote></div><br></div>