1

I've been playing a bit with TemplateHaskell and I came across this problem, which is basically

you can't do

keyword name = [d| data $(name) = $(name) |]

You have to do something like

keyword name = return [DataD [] name [] [NormalC name []] []] where
        name' = mkName name

instead.

Apparently the reason would be related to some typechecking problem. So the question is, why Template Haskell uses a complicated AST instead of just strings. Wouldn't that be easier if a splice was returning a simple string and the type checking would occur on the expanded file ?

Community
  • 1
  • 1
mb14
  • 22,276
  • 7
  • 60
  • 102
  • 5
    Yes, but you can do much more useful processing over an actual AST vs strings. Consider something like "Find all variables in this string" which means you have to actually parse haskell to do something pretty trivial – daniel gratzer May 17 '14 at 18:57
  • That's actually one of the few situations where you can't just splice in the names (although you do have to use functions like `varP` and `varE` to get the types right). – Jeremy List Oct 27 '15 at 13:16

0 Answers0