[Haskell-cafe] Precedence and associativity in a pretty-printer

Edsko de Vries devriese at cs.tcd.ie
Tue Jan 22 13:34:24 EST 2008


Suppose we have some algebraic datatype describing an expression
language containing the usual suspects (various binary arithmetic
operators such as addition, subtraction, multiplication, division,
exponentiation, function abstraction and application, etc.) each with
their own precendence (multiplication binds stronger than addition) and
associativity (function application is left associative, exponentiation
is right associative, addition is associative, etc.) 

Is there a nice way to pretty-print such an expression with the minimal
number of brackets? I can come up with something, but I'm sure somebody
thought hard about this problem before and came up with a really nice
solution :)

Any hints or pointers would be appreciated,



More information about the Haskell-Cafe mailing list