[Template-haskell] Renaming in pretty printer
cmb21 at kent.ac.uk
Tue Mar 28 13:11:24 EST 2006
> 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
> Can someone comment on why this is done?
From my knowledge its the way GHC handles identifiers. GHC's AST
does not contain source location information, so there is no way to
distinguish between different identifiers in an AST. GHC renames them
so they are unique to avoid this ambiguity. If you take another
Haskell compiler such as Programatica - Programatica gets around
using unique names for identifiers by adding location information as
well, so you can can refer to a particular identifier by its source
More information about the template-haskell