curry f a b = f(a,b)
I thought: the curry function takes function f a b and returns f(a, b), so i thought the type is:
(a -> b -> c) -> (a, b) -> c
so why the type is reversed?:
((a, b) -> c) -> (a -> b -> c)
curry f a b = f(a,b)
I thought: the curry function takes function f a b and returns f(a, b), so i thought the type is:
(a -> b -> c) -> (a, b) -> c
so why the type is reversed?:
((a, b) -> c) -> (a -> b -> c)
I believe the source of your confusion is this passage:
the curry function takes function f a b
Not really: curry
takes a function, and that function is f
. As for a
and b
, they are arguments that are passed to the curried function. It is easier to see that by either adding a pair of superfluous parentheses, to make the partial application more evident...
(curry f) a b = f (a,b)
... or by shifting a
and b
to the right-hand side with a lambda:
curry f = \a b -> f (a,b)
f
is a function that takes a pair -- note that we give it a pair, (a,b)
. curry f
, on the other hand, takes the two arguments separately. That being so, the type of curry
is indeed:
curry :: ((a, b) -> c) -> (a -> b -> c)
Curry takes only one argument which is a function and returns a function. That argument is a function with the signature
((a, b) -> c)
i.e. a function that takes one argument: a pair of things a and b and returns another thing c. Curry does something magical to that function and turns it into a new function:
(a -> b -> c)
i.e. a function that takes two arguments: a thing a and a thing b and returns a thing c.
So the code:
curry f a b
is like:
let newFunction = curry(f)
newFunction a b
Basically curry transforms a function that takes a pair into a function that takes that pair as two arguments instead.