When Calling Functions
You gotta understand that functions in SML take one thing: one tuple (even if the tuple itself is a 12-tuple), one record. So, when you call an SML function like this:
constantly 5.0 9
You are really doing this:
(constantly 5.0) 9
which is 100% the same as this:
( (constantly 5.0) 9)
When defining functions
Dont sleep when looking at a function that has spaces between its arguments. A lot is happening there. It is a fact that
val constantly = fn k => (fn a => k);
is the same as
fun constantly k a = k
An easy way to remember the expansion of "fun" is to realize that you are creating two functions. One will take "k" as an argument and the other will take "a" as an argument.
But how about a function taking 3 space-separated arguments
I saw this:
fun curry f x y = f (x, y)
but don't know how to rewrite this using value notation... could someone help ?
val curry = fn f => fn x => fn y => f (x, y)
This is why fun is useful.
-- AdamChlipala
