Haskell abstract syntax expression dynamic loading

Can we use the GHC API or something else to load non-text source modules, but AST expressions similar to haskell-src-exts Exptype ? Thus, we could save time for code generation and analysis.

+5
source share
1 answer

I don't think the GHC API provides an AST interface (maybe this is wrong), but Template Haskell does. If you create expressions using a structure Language.Haskell.TH Exp, you can create functions / declarations and use them with syntax $(someTHFunction).

A pretty serious caveat is that TH only works at compile time, so you need to pre-generate everything. If you want to use TH at run time, I think you will need to pretty much print the haskell AST template, and then use the GHC API in the resulting string.

+3
source

All Articles