我希望能够使用 hint
嵌入一个 Haskell 解释器,这样我就可以在哈斯克尔编写插件来使用我的程序。我不想为我的可执行程序运送整个 Haskell 平台。
通常,Haskell 可执行文件是非常自包含的,例如,擦除 PATH
不会引起问题:
$ PATH=. Hello
Hello world
然而,一个简单的测试程序使用 runInterpreter
炸弹,如果我删除的 PATH
:
$ PATH=. TryHint
GhcException "panic! (the 'impossible' happened)\n (GHC version 7.8.3 for x86_64-apple-darwin):\n\tDynamic linker not initialised\n\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\n"
在环境中必须有哪些库或可执行程序才能工作?
otool
没有给出太多指导:
otool -L TryHint
TryHint:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/local/lib/libgmp.10.dylib (compatibility version 13.0.0, current version 13.0.0)
TryHint
的测试代码没有太多功能:
import Control.Monad
import Language.Haskell.Interpreter
main = do
f <- runInterpreter $ loadModules ["Test"] >> setTopLevelModules ["Test"] >> interpret "f" (as :: Int -> Int)
case f of
Left e -> print e
Right r -> mapM_ (print . r) [1..10]
它只是将 f
绑定到 Test.hs
中的一个函数,以便在运行时进行解释:
module Test where
f :: Int -> Int
f x = x + 1