[Template-haskell] Renaming in pretty printer

Simon Peyton-Jones simonpj at microsoft.com
Mon Apr 10 11:46:32 EDT 2006


I've no idea.  It certainly seems that Language.Haskell.TH.PprLib
implements a pretty-printing Doc type that does renaming as it goes.  I
guess that he wanted to have shorter variable names.

It's done using a state monad, which looks fragile to me: it appears to
rely utterly on printing TH syntax trees with NameUs that do not involve
shadowing; which is probably the case, but is not part of the
specification.  I'm not sure who wrote it: Don Stewart perhaps.

Simon

| -----Original Message-----
| From: template-haskell-bounces at haskell.org
[mailto:template-haskell-bounces at haskell.org] On
| Behalf Of Andy Gill
| Sent: 28 March 2006 18:58
| To: template-haskell at haskell.org
| Subject: [Template-haskell] Renaming in pretty printer
| 
| Template Haskell appears to be doing renaming during pretty printing.
| Take this example, that both prints the AST directly, as well as
| pretty printing.
| 
| *Main> runQ ([| let x = 1 in x |]) >>= \x -> print (pprint x,x)
| ("let x_0 = 1\n in x_0",LetE [ValD (VarP x_7) (NormalB (LitE
| (IntegerL 1))) []] (VarE x_7))
| 
| The var x has name x_7 in the AST, but x_0 in the pretty printed
| version.
| 
| Can someone comment on why this is done?
| 
| Andy Gill


More information about the template-haskell mailing list