Swift should support currying/partial application for default infix operators
| Originator: | kurz | ||
| Number: | rdar://17729052 | Date Originated: | 18-Jul-2014 08:49 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6 Beta 3 |
| Classification: | Enhancement | Reproducible: | Always |
Summary: It should be easy to partially apply an operator(-function) like '*' or '+' Steps to Reproduce: Write the following code in Swift: let addTwo: Int -> Int = (+)(2) let timesTwo: Int -> Int = (*)(2) let a = addTwo(3) let b = timesTwo(3) let listA = [2,3,5,10].map(addTwo) let listB = [2,3,5,10].map(timesTwo) Expected Results: The code compiles and creates partially applied versions of the predefined operator functions Actual Results: Compiler error: Playground execution failed: error: <EXPR>:16:27: error: 'UInt8' is not convertible to 'Int -> Int' let addTwo: Int -> Int = (+)(2)
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!
It would be nice if Swift had better built-in support for partial application and currying. FWIW, here are some little functions I've written to sorta do this:
Do you have expected results and actual results reversed here?
I follow this radar until expected results.
got the expected and actual the wrong way round. Fixed that now.