Functions in Swift should be curried by default without the need for special syntax.

Originator:injahta
Number:rdar://17223324 Date Originated:06/08/2014
Status:Open Resolved:
Product:Swift Product Version:
Classification: Reproducible:
 
Summary:
Functions in Swift can be curried using special syntax such as follows:

func addTwo(a:Int)(b:Int) -> Int {
    return a + b
}

or

func addTwo(a:Int) -> (Int -> Int) {
    func add(b:Int) -> Int {
        return a + b
    }
    return add
}

However, it would be more desirable if all functions were able to be curried without special declaration, such that:

func addTwo(a:Int, b:Int) -> Int
is equivalent to
func addTwo(a:Int) -> (Int -> Int)

This should extend to all functions.

Steps to Reproduce:
1. Declare a function such as func addTwo(a:Int, b:Int) -> Int
2. Set it like so: let curried = addTwo(1)

Expected Results:
The curried constant is a function that takes a single Int and adds one to it.

Actual Results:
A complier error that states: "Cannot convert the expression's type 'Int' to type '(Int, Int)'"

Comments

Wouldn't that break together with default arguments?

func addTwo(a:Int, b:Int = 2);

var x = addTwo(2) // is x an Int or an Int -> Int?


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!