Preferred method for viewing code generated by Template Haskell
Are you looking for the -ddump-splices flag to the compiler?
Are you looking for the -ddump-splices flag to the compiler?
This would be nice to have but it isn’t currently possible in GHC.
Since so many people are interested in the question, I’ll add my current approach, perhaps somebody will find it useful. Probably the best way would be if TH allowed to read -D parameters on GHC’s command line, but it seems nothing like this is currently implemented. A simple module allows TH to read compile-time environment. … Read more
Unfortunately, you cannot do this with TH alone. Try the haskell-src-meta to parse the Haskell module as a TH AST. It will require the IO features of the Q monad to load the module though. Please reference https://ghc.haskell.org/trac/ghc/ticket/9699#ticket to see the current rough spec (1) Extend ​ModuleInfo (obtained from ​reifyModule) to ModuleInfo [Module] [Name], where … Read more
It is not implemented because nobody requested it. The odd thing is that TH uses its own AST, which doesn’t follow internal compiler’s AST. As a result, any new feature (e.g. associated type families) is not automatically available via TH. Some one have to open a ticket and implement it. For the reference: internal reifyClass … Read more
One reason for avoiding Template Haskell is that it as a whole isn’t type-safe, at all, thus going against much of “the spirit of Haskell.” Here are some examples of this: You have no control over what kind of Haskell AST a piece of TH code will generate, beyond where it will appear; you can … Read more