RE: Renaming in pretty printer

"Simon Peyton-Jones" <[email protected]> Mon, 10 Apr 2006 16:46:32 +0100
Newsgroups gmane.comp.lang.haskell.template
Message-ID <036EAC76E7F5EC4996A3B3C3657D41160514F96F@EUR-MSG-21.europe.corp.microsoft.com>
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: [email protected]
[mailto:[email protected]] On
| Behalf Of Andy Gill
| Sent: 28 March 2006 18:58
| To: [email protected]
| 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