Currying requires external parameter, even though there is none
| Originator: | lucasderraugh | ||
| Number: | rdar://17458161 | Date Originated: | |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: |
Summary:
When currying a function, the external parameter is required in the case of the second parameter
Here's an example:
func add(x: Int)(y: Int) -> Int {return x+y}
let incrementBy2 = add(2)
let val = incrementBy2(10) // Error: requires 'y:' even though it's not an external parameter
To resolve this issue you can type:
let val = incrementBy2(y: 10)
But this makes no sense and it makes currying a rather useless feature when there has to be (potentially) arbitrary names attached to the parameters
Steps to Reproduce:
1. Run playground file (or code above)
2. Observe error (Missing argument label 'y:' in call)
Expected Results:
Not to have the need for the 'y:' as a parameter since it is not an external parameter
Actual Results:
Error: Missing argument label 'y:' in call
Version:
Xcode 6 Beta 2
Version 6.0 (6A216f)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Workaround
FWIW, you can work around this limitation by "manually currying" the function:
But it would be nice if Swift's currying syntax handled this.