The language reference section on Binary Operators has some information that may be incorrect:
Operator alias declarations are made up of five parts:
- …
- The precedence: an integer, between 0 and 9…
- …
or confusing:
Infix operators created using backticks are left associative with the highest precedence.
result = 1 `add` 2 * 3 -- == 9
(I interpret “the highest precedence” here as “the highest precedence assignable to an operator,” which is how it works in Haskell, but I don’t know if that’s how others read it.)
I put together a few tests (GitHub, TryPureScript) that suggest:
- Precedence can be any (arbitrarily large) non-negative integer (
a
,b
,c
,d
,e
) - Backtick expressions have a higher precedence than all operators (
f
,g
,h
,i
)
(Also, I don’t think this was in question, but I included some tests showing that function application has higher precedence than backtick expressions (j
, k
).)
The tests cover several edge cases, but I like this one a lot:
infixr 2147483648 mul as *^*
h = 1 `add` 2 *^* 3 -- == 9
Did I miss anything? Is this a compiler bug or should the documentation be updated?