The number that follows the associativity information describes in what order the operators are applied. It must always be between 0
and 9
inclusive. This is commonly referred to as how tightly the operator binds. For example, consider the following fixity declarations (in base)
infixl 6 +
infixl 7 *
Since *
has a higher binding precedence than +
we read 1 * 2 + 3
as
(1 * 2) + 3
In short, the higher the number, the closer the operator will "pull" the parens on either side of it.
Function application always binds higher than operators, so f x `op` g y
must be interpreted as (f x)
op(g y)
no matter what the operator `op`
and its fixity declaration are.
If the binding precedence is omitted in a fixity declaration (for example we have infixl *!?
) the default is 9
.