[Haskell-cafe] haskell-src-exts Question

Dominic Steinitz dominic at steinitz.org
Fri Nov 13 03:49:31 EST 2009


I've been generating Haskell using haskell-src-exts but the prettyprinter isn't 
producing what I would expect.

I would expect parse . prettyPrint == id i.e. the AST should be unchanged if 
you prettyprint it then parse it.

Here's an example generated expression:

App (App (Var (UnQual (Ident "pay"))) (Var (UnQual (Ident "tPD")))) (App (Var 
(UnQual (Ident "a"))) (InfixApp (App (Var (UnQual (Ident "length"))) (Var 
(UnQual (Ident "tOD")))) (QVarOp (UnQual (Symbol "+"))) (Lit (Int (-1)))))

Here's what prettyPrint produces:

pay tPD a length tOD + -1

Parsing it gives this (i.e. not the expression I first thought of):

InfixApp (App (App (App (App (Var (UnQual (Ident "pay"))) (Var (UnQual 
(Ident "tPD")))) (Var (UnQual (Ident "a")))) (Var (UnQual (Ident "length")))) 
(Var (UnQual (Ident "tOD")))) (QVarOp (UnQual (Symbol "+"))) (NegApp (Lit (Int 
1)))

I would have expected the prettyprinter to produce this:

pay tPD (a (length tOD + -1))

Do I have to write my own prettyprinter? Do I have to put in explicit 
parentheses? The latter seems unsatisfactory as my generated AST is unambiguous 
and bracketing ought to be part of the prettyprinter. The former would be quite 
a lot of code as there are many cases to consider.

Dominic.



More information about the Haskell-Cafe mailing list