[Haskell-cafe] Numeric vs. relative precedences of infix operators
karczma at info.unicaen.fr
karczma at info.unicaen.fr
Mon Feb 28 10:05:25 EST 2005
Henning Thielemann writes:
> Is it widely accepted that the precedence of infix operators is defined by
> numbers? The numbers look arbitrary to me and it is not possible to
> introduce infix operators with interim precedences.
> What about defining relations such as "(*) has precedence over (+)"? The
> compiler could construct a topographically ordered graph from these
> relations.
"Widely accepted" is a widely accepted relativism...
I am also annoyed by the precedences 0,1,2, ...,9, etc.
Why not 10, 20, 30,... ??
When I taught compilation, I suggested to use pairs (lprec,rprec) to denote
simultaneously the precedence and the associativity. The parsing becomes
quite homogeneous. (This is a very old idea, not mine, obviously...)
Of course, there is a necessity to define the non-associativity as well...
Some partial ordering is needed. But in this style it is even possible to
declare "bracketing" operators. If the lprec of the second is equal to
lprec of the first, then *both* operators are reduced. Parentheses become
operators as all others...
Jerzy Karczmarczuk
More information about the Haskell-Cafe
mailing list