0

You can see in this simple example how it renames the type and value constructors from A to A_0 and A_1 while converting from expression quotation to AST:

Prelude Language.Haskell.TH> runQ [d|data A = A|]
[DataD [] A_0 [] [NormalC A_1 []] []]

How can enforce the names to stay the way I specify?

Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
  • `[d| data A = A|]` at top-level makes a `data A = A`, without the _1 or _0. If you're doing other stuff with the Dec first, I guess you can change the `NameFlavour` or ignore it. – aavogt Nov 02 '13 at 05:01

1 Answers1

1

The name mangling is similar to what "Hygienic macros" feature is called in Lisp world, where the names used in the macro emitted code are mangled so that they don't interfere with the same named symbols in the code where the macro was used.

The template haskell syntax is basically a shortcut to generate normal data types defined in TH package. In you example you can use something like this to have the name you want:

runQ (return $ [DataD [] (mkName "A") [] [NormalC (mkName "A") []] []])

But remember this can lead to name collision if the code that uses this macro has already a data deceleration called A.

Ankur
  • 33,367
  • 2
  • 46
  • 72