Currying

Before last week I thought of curry as a delicious spice… from this point forward I will now think of a programming language feature. I’m currently adding support for currying in Blaise. A Blaise programmer can invoke a function with too few or too many arguments. Doing so causes a function to return a partial application instead of a value for a fully saturated function call. Later on the developer can invoke the partial application and pass the rest of necessary arguments to it. Wikipedia has a pretty good explanation on currying.

Here’s an example of currying with Ocaml-ish syntax:

let f arg1 arg2 arg3 =
    (* body of code *)
;;
let x = (f 1 2);;
let y = (x 3);;

Notice how the first time I invoke f I didn’t pass three arguments. x will become a partial application. Later, x, the partial application, is called with one argument – giving the function f a third argument it is invoked. The following line of code will result with y attaining the same value as the code above.

let y = (f 1 2 3);

Leave a Reply