[Haskell-cafe] haskell-src-exts Question
Sebastian Fischer
sebf at informatik.uni-kiel.de
Mon Nov 16 06:03:04 EST 2009
Hello,
On Nov 13, 2009, at 11:54 PM, Niklas Broberg wrote:
> 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.
If I was planning to write a Haskell program that generates Haskell
code, should I use HSE? Or is it more for generating nice looking code
than correct code? Is there an alternative package that is more
suitable for generating code that is meant to be executed rather than
being looked at?
> 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?
Personnaly, I would prefer Duncans approach to produce correct output
by default and require additional fixity information if the output
should contain fewer parens. (The reason for my preference is that I
think it is quite annoying to insert parens manually into auto
generated infix applications only to get correct output.)
In order to help reducing the amount of annoying parentheses in
printed code, would it be sufficient - at least for the common case -
to do something along the lines of
prettyPrint = prettyPrintWithFixities preludeFixities
and provide make `prettyPrint`, `prettyPrintWithFixities`, and
`preludeFixities` public?
Cheers,
Sebastian
--
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)
More information about the Haskell-Cafe
mailing list