You might not have ever seen this before!!
let add x y = x + y;;
val add : int -> int -> int = <fun>
This is a pretty simple function, it adds two integers.
add 2;;
- : int -> int = <fun>
Wait... what happened here? add 2 produces a <fun>, which has the argument 2 bound to it!
(add 2) 5;;
- : int = 7
We can break this down to several steps to make it easier to understand!
let add_two = add 2;;
val add_two : int -> int = <fun>
add_two 5;;
- : int = 7
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.