What does "curried" mean?

The async-await proposal has this sentence:

If the reference is a “curried” static reference to an instance method, it is the "inner" function type that is async , consistent with the usual rules for such references.

What does "curried" mean here?

1 Like

But what’s the currying of a reference?

Consider the code example:

struct S {
    func f(_ y: Int) -> Int { return y }

let g = S.f
let x = g(S())
let y = x(10)

This is like currying in functional programming -- the method gets treated as if it takes self as an argument and returns a function which takes another argument, instead of taking self and the other argument both at once. Here g (equivalently S.f) is the curried function reference.

If I'm understanding the statement correctly, what the quoted sentence is saying is that if f is declared as an async method on an actor, then its type will be (S) -> ((Int) async -> Int) and not (S) async -> ((Int) -> Int), because the "inner function type" is (Int) -> Int.


The practical answer is that currying makes creating anonymous functions much easier. Even with a minimal lambda syntax, it's something of a win; compare:

map (add 1) [1..10]
map (\ x -> add 1 x) [1..10]

If you have an ugly lambda syntax, it's even worse. (I'm looking at you, JavaScript, Scheme and Python.)