Function and production invocation

Quick examples:

append([1,2], [3,4])
fromMaybe(1, just(2))
cons(1, cons(2, nil()))


Functions and productions are invoked with identical syntax, which is similar to C/Java’s (i.e. uncurried):

expression ( expressions... )

Example: invoking the substring function, with three arguments.

substring(1, 5, "/path/file")

Example: passing foo as a parameter to either a or b, depending on the value of cond.

(if cond then a else b)(foo)

Example: constructing trees (given suitable productions add and mul):

mul(add(1,2), 3)

Note that production application necessarily produces the undecorated type of the nonterminal it constructs. (See Decorated vs Undecorated for more on the distinction between decorated and undecorated.)

Partial Application

Missing arguments replaced by underscores will result in a partially-applied function.

map(add(3,_), [1,2])  =  [add(3,1), add(3,2)]
fun(_,_)  =  fun

Arguments supplied in a partial application are only evaluated once, so any expensive computation will be reused by the other applications of the same resulting function value.


Annotations are supplied to a production as named parameters after the ordered parameters.

add(l.ast, r.ast, location=this.location)

Named annotation parameters can also be converted to ordered parameters in a partial application:

add(_, _, location=_)