λ

1.5: Fun with Functions

As the single argument fn form is harder to work with, there is syntactic sugar for declaring functions of any number of arguments: fun. Here we declare add, which has the same behaviour as the add from before, but with a simpler definition. Function arguments may be given type declarations if desired, but they are not necessary, as SML can infer them.

Functions may accept a tupled argument, to create an uncurried function, and return any number of results using a tuple. Tupled arguments may be provided with type declarations if desired.

All functions in Standard ML must accept at least one value, and produce at least one value, but you may not need them, as in a print function. In that case, you may accept a unit value as input, and return unit (()) as the result.

Refer to an operator, such as +, by using the op keyword.

(* examples/fun.sml *)