A function application
f a1 a2 anapplies the function
fto the arguments
The above syntax is valid where
fis aregular identifier.If the function name is an operator such as
*,then the syntax for application is infix :
a1 * a2.Any operator can be used in prefix position by surrounding it in parentheses:
(*) a1 a2.
All Unison functions are ofarity1. That is, they take exactly one argument. An n-ary function is modeled either as a unary function that returns a further function (a partially applied function) which accepts the rest of the arguments, or as a unary function that accepts a tuple.
Function application associates to the left, so the expression
f a bis the same as
(f a) b.If
T1 -> T2 -> Tnthen
f ais well typed only if
T1.The type of
f ais then
T2 -> Tn.The type constructor of function types,
->,associates to the right. So
T1 -> T2 -> Tnparenthesizes as
T1 -> (T2 -> TN).
The evaluation semantics of function application is applicative orderCall-by-Value.In the expression
f x y,
yare fully evaluated in left-to-right order, then
fis fully evaluated, then
yare substituted into the body of
f,and lastly the body is evaluated.
An exception to the evaluation semantics isBoolean expressions,which have non-strict semantics.
Unison supportsproper tail callsso function calls in tail position do not grow the call stack.
The arity of a function or data constructor describes the number of arguments that it takes.
For example, the function
addThree : Nat -> Nat -> Nat -> Natis a function of arity 3.
Some arities are common enough they get special terms:
- A "nullary" function has 0 arguments
- A "unary" function has 1 arguments
- A "binary" function has 2 arguments
- A "ternary" function has 3 arguments