Category Archives: Honors Project

Currying Known Functions

Currying for known functions in Blaise is now supported! Implementing this functionality wasn’t too hard. My largest obstacle was writing the proper OCaml syntax in the compiler. I understood the logic of my problem shortly after receiving my assignment but, since I’m not an avid functional programmer there were a few quirks in OCaml that I need to get used to.

Now I’m going to support currying for unknown functions. This will be a bit more difficult and I have to do a bit of research to figure out how to implement this feature.

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);

Blaise Compiler

Today I had my first meeting with Professor Stump to determine what I’ll work on this fall: a compiler for a functional programming language. My first task is to add currying support to the Blaise Compiler. Currying allows the programmer to call a function with too few, too many, or just enough arguments at invocation, this will be explained further in future posts.