A function applicationf a1 a2 an
applies the functionf
to the argumentsa1
throughan
.
The above syntax is valid wheref
is 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 expressionf a b
is the same as(f a) b
.Iff
has typeT1 -> T2 -> Tn
thenf a
is well typed only ifa
has typeT1
.The type off a
is thenT2 -> Tn
.The type constructor of function types,->
,associates to the right. SoT1 -> T2 -> Tn
parenthesizes asT1 -> (T2 -> TN)
.
The evaluation semantics of function application is applicative orderCall-by-Value.In the expressionf x y
,x
andy
are fully evaluated in left-to-right order, thenf
is fully evaluated, thenx
andy
are substituted into the body off
,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.