09 Partial Application

You might not have ever seen this before!!

This is a pretty simple function, it adds two integers.

Wait... what happened here? add 2 produces a <fun>, which has the argument 2 bound to it!

We can break this down to several steps to make it easier to understand!

Wait why does that work? It's because Prof. Clarkson has been lying to us

Multi-argument functions don't exist.

fun x y -> e;;

is really just syntactic sugar for

fun x -> (fun y - e);;

Applied:

let add x y = x + y

is really syntactic sugar for

let add = fun x ->
    fun y ->
        x + y;;

This generalizes to any number of arguments.

This is really just a consequence of functions being values.

We're really just passing functions around.