19.1 Elaboration of infix expressions
The following infix declamations give identifiers in the vid class infix operator property.
infix n vidSeq
infixr n vidSeq
infix defines vidSeq as left associative infix operators and infixr defines vidSeq as right associative infix operators. Optional integer n (from to ) specifies association strength (with the strongest). If is omitted then is assumed. Declaration
nonfix vidSeq
cancel infix operator property of identifiers vidSeq.
Infix expressions are converted to applications to tuples according to the association strength.
source | result |
---|---|
exp vid exp | op vid (exp,exp) |
pat vid pat | op vid (pat,pat) |
The syntax, when appears in expressions and patters,
op vid
cancel the infix status of vid. Therefore if the identifier foo has infix status, then the following two code fragments are equivalent.
1 foo 2
op foo (1,2)
The following are implicitly declared in all the compilation unit and the interactive mode.
infix 7 * / div mod
infix 6 + -^
infixr 5 :: @
infix 4 = <> > >= < <=
infix 3 := o
infix 0 before
The above hierarchical syntax with infix declarations determines the association strength of expressions. For example, record update expression (exp # {lab=exp}) associates tightly than strongest infix operators (those that are declared with infix 9), and expression constructs if exp thenexp else exp and others associates weakly than weakest infix operators (those that are declared with infix 0.