带Haskell的动态代码加载

时间:2015-03-25 17:47:15

标签: haskell dynamic-loading dynamic-compilation

我一直在玩plugins套餐。我希望主机应用程序在沙盒环境中动态编译和加载Haskell源文件。编译工作正常。只要插件仅引用沙箱中可用的模块,加载就会失败。以下是我为插件所获得的内容:

module Plugin (resource) where

import ServerAPI
import System.Plugins -- this module is only available in the sandbox

resource = Interface { action = timesTwo }

timesTwo :: Integer -> IO Integer
timesTwo n = return $ n * 2

从主机应用程序加载插件如下所示:

pkgConfDir = "/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
loadedOk <- pdynload "Plugin.o" ["."] [pkgConfDir] "ServerAPI.Interface" "resource"

这就是我在沙箱中所得到的:

> cabal sandbox hc-pkg list
…
/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
    plugins-1.5.4.0
…

这是我在运行主机应用程序时得到的结果:

Failed to load interface for ‘System.Plugins.Env’
no package matching ‘plugins-1.5.4.0’ was found

如上所述,当我删除插件中的import System.Plugins语句时,代码会加载。我错过了什么?

编辑:

cabal文件:

name:                plugins
version:             0.1.0.0
-- synopsis:
-- description:
-- license:
license-file:        LICENSE
author:              W. Davis
maintainer:          w.davis@spam.me.not
-- copyright:
-- category:
build-type:          Simple
-- extra-source-files:
cabal-version:       >=1.10

executable plugins
  main-is:             Main.hs
  -- other-modules:       
  -- other-extensions:
  build-depends:       base >=4.7 && <4.8, plugins >=1.5 && <1.6
  -- hs-source-dirs:
  default-language:    Haskell2010

0 个答案:

没有答案