如何使用Language.Haskell.Interpreter发送可执行文件?

问题描述 投票:136回答:1

我希望使用hint嵌入一个Haskell解释器,这样我就可以在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中的函数,以便在运行时进行解释。 Test.hs看起来像这样:

module Test where
f :: Int -> Int
f x = x + 1
haskell packaging shipping
1个回答
2
投票

使用Language.Haskell.Interpreter发送可执行文件似乎与您展示的方式完美无缺。您必须将PATH设置为要执行的脚本。

正如旁注所示,正如@bennofs在评论中所提到的,静态链接GHC API不适用于GHC 7.8中引入的新动态链接器(交互式代码执行现在需要动态库)。

© www.soinside.com 2019 - 2024. All rights reserved.