加载动态haskell模块
我正在寻找一种从字符串加载 Haskell 函数来运行的方法。我事先知道类型,但不知道函数的内容。
理想情况下,解决方案应该很快并且不需要在 IO 中运行。
我一直在查看提示(Language.Haskell.Interpreter),但它不符合法案(eval 调用显示,模块必须位于文件中)。
任何帮助将不胜感激。
I'm looking for a way to load a Haskell function from a string to run. I know the type before hand, but don't know the contents of the function.
Ideally, a solution would be quick and not need to run in IO.
I've been looking at hint (Language.Haskell.Interpreter), but it doesn't fit bill (eval calls show, modules must be in files).
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提示
和plugins
是主要选项。hint
允许您将函数解释为字节码,plugins
使用编译的目标代码。请注意,由于这些“eval”函数在运行之前必须进行类型检查,因此它们很少是纯值,因为评估可能会因类型错误而失败。
hint
andplugins
are the main options.hint
lets you interpret functions as bytecode,plugins
uses compiled object code.Note that since these 'eval' functions must be type-checked prior to running them, they're rarely pure values, as evaluation may fail with a type error.
抽象的答案是,您只需使
(->)
成为阅读
(可能还有Show while you're at it)我不知道你到底应该怎么做。解释代码可不是一件小事。
如果您正在处理简单的函数,我建议创建一个代数数据类型来表示它们。
The abstract answer is that you just have to make
(->)
an instance ofRead
(and possibly Show while you're at it)How on earth you are supposed to do that, I don't know. It's no small task to interpret code.
If you are dealing with simple functions, the I would suggest creating an algebraic data type to represent them.