Groovy has a concept that it calls 'currying'. Here's an example from their wiki:
def divide = { a, b -> a / b }
def halver = divide.rcurry(2)
assert halver(8) == 4
My understanding of what's going on here is that the right hand argument of divide
is being bound to the value 2. This seems like a form of partial application.
The term currying is usually used to mean transforming a function that takes a series of arguments into a function that only takes one argument and returns another function. For example here is the type of the curry
function in Haskell:
curry :: ((a, b) -> c) -> (a -> (b -> c))
For people who haven't used Haskell a
, b
and c
are all generic parameters. curry
takes a function with two arguments, and returns a function that takes a
and returns a function from b
to c
. I've added an extra pair of brackets to the type to make this more clear.
Have I misunderstood what's going on in the groovy example or is it merely misnamed partial application? Or does it in fact do both: that is to say convert divide
into a curried function and then partially apply 2
to this new function.