Haskell抽象语法表达式的动态加载 [英] Dynamic loading of Haskell abstract syntax expression
问题描述
我们可以使用GHC API或其他的东西来加载文本源模块,但是AST表达式类似于 haskell-src-exts Exp type
?这样我们可以节省代码生成和解析的时间。我不认为GHC API公开了AST接口(可能是错误的),但模板Haskell的确。如果使用 Language.Haskell.TH
Exp
结构构建表达式,则可以创建函数/声明并利用它们由 $(someTHFunction)
语法。
一个相当重要的警告是TH仅在编译时运行,所以你需要预先生成一切。如果您想在运行时使用TH,我认为您需要漂亮地打印模板haskell AST,然后在结果字符串中使用GHC API。
Can we use GHC API or something else to load not text source modules, but AST expressions, similar to haskell-src-exts Exp
type? This way we could save time for code generation and parsing.
I don't think the GHC API exposes an AST interface (could be wrong though), but Template Haskell does. If you build expressions using the Language.Haskell.TH
Exp
structure, you can create functions/declarations and make use of them by the $(someTHFunction)
syntax.
A fairly major caveat is that TH only runs at compile time, so you would need to pre-generate everything. If you want to use TH at run-time, I think you'd need to pretty-print the template haskell AST, then use the GHC API on the resulting string.
这篇关于Haskell抽象语法表达式的动态加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!