Generating valid Haskell code using the GHC API pretty printer

Jan Schaumlöffel jsch at informatik.uni-kiel.de
Tue Aug 18 06:20:02 EDT 2009


Hello,

sorry for the delay in replying, I have been away from my computer
during the last weeks.

Simon Peyton-Jones wrote:
> I've fixed GHC's pretty-printer to print do-notation using braces
> and semi-colons, which is much more robust.  I hope that's useful

This is certainly useful, and it seems to fix the issues for me.
Thank you very much!

Thomas Schilling wrote:
> That said, if you're trying to do source-to-source transformations
> you probably want to keep the original layout as much as possible.
> GHC's pretty-printer isn't designed for that.  GHC's syntax tree has
> very accurate source locations, so you could start from there and
> build your own pretty printer.

Niklas Broberg wrote:
> In general, unless you actually want to use any other components of
> the GHC API, e.g. evaluate your code, then I see no reason to use
> the GHC API for source manipulation. haskell-src-exts simply does
> that better (and definitely better than haskell-src). But I couldn't
> tell if that's enough for the original poster's needs. :-)

Well, the application is a debugger for Concurrent Haskell programs.
It reads a program and replaces certain function calls with calls to
location-aware wrappers that allow stepping the program and
highlighting the original source location.  The result of this
transformation is then compiled and executed; it is not intended to be
seen by the user (who is shown the original source).

So I guess what we need is not a "pretty printer" but a "valid
printer".  We need accurate original source locations and we need to
access the syntax tree after typechecking to be able to tell which
functions to replace.  The GHC API looked like the way to go and it
does so even more with Simon's patch.

Thanks for your input,

Jan

-- 
If you're happy and you know it, syntax error!


More information about the Glasgow-haskell-users mailing list