[swift-evolution] SE-0111 and Curried argument labels: Unintended Consequences

Michael Ilseman milseman at apple.com
Tue Oct 4 11:37:14 CDT 2016


> On Oct 4, 2016, at 9:32 AM, Michael Ilseman via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> On Oct 4, 2016, at 9:21 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> SE-0111 established that Swift's type system would not allow function argument labels to be expressed as part of a function type. As I've been working with curried functions, I'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.
>> 
>> ```
>> public func projected(
>>     function f: @escaping (CGFloat) -> CGFloat) ->
>>     (_ p0: CGPoint, _ p1: CGPoint) -> 
>>     (_ percent: CGFloat) -> CGPoint
>> {
>> ```
>> 
>> Calling the first level of currying still reads acceptably:
>> 
>> ```
>> let projectedFunction = projected(function: fToApply)
>> ```
>> 
>> 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:
>> 
>> ```
>> let fixedFunction = projectedFunction(p0, p1)
>> let value = fixedFunction(0.2)
>> ```
>> 
>> There'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.
>> 
>> Could this be addressed specifically for currying or has the boat sailed forever on this topic?
>> 
> 
> This could be expressed by allowing local variable names to have compound names when of function type. I would not require it to be expressed this way, but it would be a nice addition. This would look something like the following:
> 
> let projectedFunction(from:to:) = projected(function: fToApply)
> let scale(by:) = projectedFunction(from: myPoint1, to: myPoint2)
> let finalPoint = scale(by: 3.0)
> 
> When it comes to local assignment, it makes sense to allow local control over argument labels. For people who don’t care to have their closures be applied with labels, maybe allow current syntax:
> 
> let projectedFunction = projected(function: fToApply)
> let scale = projectedFunction(myPoint1, myPoint2)
> let finalPoint = scale(3.0)
> 
> I’m not sure if we want to force compound names always (demonstrate arity and explicit label-less-ness), but one could envision a strict enforcement like:
> 
> let projectedFunction(_:_:) = projected(function: fToApply)
> let scale(_:) = projectedFunction(myPoint1, myPoint2)
> let finalPoint = scale(3.0)
> 

To clarify, I’m not in favor of strict enforcing of this final form, and it would need extreme justification to make that pitch. But, it might be possible to encourage that form in linting tools. And, if there is strong, albeit not extreme, justification, enforce through a warning/fix-it).


> 
> Probably out of scope for Swift 4 stage 1
> 
> 
>> -- E
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161004/fb93e6c7/attachment.html>


More information about the swift-evolution mailing list