[Haskell-cafe] haskell-src-exts Question

Niklas Broberg niklas.broberg at gmail.com
Fri Nov 13 17:54:00 EST 2009


> Surely you do want this. It's the biggest problem with the original
> haskell-src package, that it cannot print out any useful Haskell code
> obtained from the parser, because it forgets all the brackets.

I should point out that haskell-src-exts already fixes this for code
obtained from the parser, by making the parser and AST remember the
brackets. Or as you put it:

> It probably wants to be a combination of the parser, AST and pretty
> printer.

Yes indeed.

But the problem at hand here is auto-generated AST code, where we
cannot rely on the parser to do the right thing. There's help in the
AST such that it's possible to explicitly insert brackets where
needed, but I agree with Dominic that it shouldn't really be necessary
in his case. Neil's point is well taken though - to do it correctly
(or rather, minimally) for infix application, the pretty printer would
need to be aware of the respective fixities involved.

However, that doesn't mean we can't do better than what it is now, but
be conservative about it. Only insert brackets where it's clear that
brackets must be inserted, which would be the case for Dominic's
example. If the argument to an application is non-atomic, it needs
brackets, there's nothing ambiguous about that. Nothing can be said so
categorically for infix applications, so there we should assume that
the fixities are already done in the correct way, or that brackets are
inserted manually where needed.

Does that sound reasonable?

Cheers,

/Niklas


More information about the Haskell-Cafe mailing list