Given a function f of arity n, the standard syntax for applying f to n arguments v_1, ..., v_n is f(v_1, ..., v_n). It is, however, allowed in ATS to use infix notation for a binary function application, and prefix or postifix notation for a unary function application.
In ATS, each identifier can be assigned one of the following fixities: prefix, infix and postfix. The fixity declarations for many commonly used identifiers can be found in $ATSHOME/prelude/fixity.ats. We often use the name operator to refer to an identifier that is assigned a fixity.
For instance, we use the following syntax to declare that + and - are infix operators of precedence value 50:
infixl 50 + -After this declaration, we can write an expression like 1 + 2 - 3, which is parsed into -(+(1, 2), 3) in terms of the standard syntax for function application. The keyword infixl indicates that the declared infix operators are left-associative. For right-associative and non-associative infix operators, please use the keywords infixr and infix, respectively. If the precedence value is omitted in a fixity declaration, it is assumed to equal 0.
We can also use the following syntax to declare that iadd, fadd, padd and uadd are left-associative infix operators with a precedence value equal to that of the operator +:
infixl (+) iadd fadd padd uaddThis is useful as it is difficult in practice to remember the precedence values of (a large collection of) declared operators.
We can also turn an identifier id into a non-associative infix operator (of precedence value 0) by putting the backslash symbol \ in front of it. For instance, the expression $exp_1 \id $exp_2 stands for id ($exp_1, $exp_2), where $exp_1 and $exp_2 refer to some expressions, either static or dynamic.
The syntax for declaring (unary) prefix and postfix operators are similar. For instance, the following syntax declares that ~ and ? are prefix and postfix operators of precedence values 61 and 69, respectively:
prefix 61 ~ postfix 69 ?For a given occurrence of an operator, we can deprive it of its assigned fixity by simply putting the keyword op in front of it. For instance 1 + 2 - 3 can be writen as op- (op+ (1, 2), 3). It is also possible to (permanently) deprive an operator of its assigned fixity. For instance, the following syntax does so to the operators iadd, fadd, padd and uadd:
nonfix iadd fadd padd uaddLastly, please note that all the fixity declarations are lexically scoped.