Why Template Haskell uses AST

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 ?

链接地址: http://www.djcxy.com/p/33182.html

上一篇: 为什么模板Haskell会添加意外的对象?

下一篇: 为什么模板Haskell使用AST