SML# Document Version 4.1.0
19 Expressions

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 0 to 9) specifies association strength (with 9 the strongest). If n is omitted then 0 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
 exp1 vid exp2 op vid (exp1,exp2)
pat1 vid pat2 op vid (pat1,pat2)

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 (exp1 # {lab=exp2}) 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.