帮助Haskell动态插件加载 [英] Help with Haskell dynamic plugin load
问题描述
我是一名Haskell初学者,我试图在'plugins'包中使用动态加载。我有点迷路。这是一个包含两个文件的最小程序。
Main.hs:
module Main(main)其中
import System.Plugins
$ b $ main :: IO()
main = do
putStrLnLoading
mv< - dynloadPlug.o[] []thing - 也尝试'load'
putStrLnLoaded
大小写
LoadFailure消息 - > putStrLn失败>>打印消息
LoadSuccess _ v - > putStrLn成功>> print(v :: Integer)
和Plug.hs:
模块插件(东西)其中
东西::整数
东西= 1234000
我使用 ghc -c Plug.hs
编译Plug,它会生成Plug.o.然后用 ghc -o Main Main.hs
编译Main.hs,然后运行Main。我也尝试用 dynload
替换 load
,并使用 runhaskell
。这四种组合中只有一种有效。我做错了什么?
- with
dynload
- 已编译→打印Loaded,然后seg故障
- runhaskell→使用
加载$ c打印加载,然后Main.hs:Prelude.undefined
$ c> - 已编译→成功,打印整数
- runhaskell→打印加载,挂起5-10秒,消失
m在Mac OS X. GHC版本7.0.2。我做错了什么?
感谢,
Rob
更新
通过将Plug.hs更改为以下内容,我可以修复已编译的 dynload
...
模块Plug(thing)其中
import Data.Dynamic
thing :: Dynamic
thing = toDyn(1234000 :: Integer )
如果错误不会导致错误,那将会很好。我想它在Plug.o中没有足够的元数据来检查类型。无论如何,这留下了 runhaskell
的情况。我为这些人提交了错误。
load
同时运行或通过 runhaskell
给我提供了Prelude.undefined错误,所以我认为您应该报告错误给开发人员。 我看不到任何特殊情况,也没有在模块的条件 haddock 文档,所以我认为你没有做错任何事情。
I'm a Haskell beginner, and I'm trying to use the dynamic loading in the 'plugins' package. I'm kind of lost. Here is a minimal program with two files.
Main.hs:
module Main (main) where
import System.Plugins
main :: IO ()
main = do
putStrLn "Loading"
mv <- dynload "Plug.o" [] [] "thing" -- also try 'load' here
putStrLn "Loaded"
case mv of
LoadFailure msgs -> putStrLn "fail" >> print msgs
LoadSuccess _ v -> putStrLn "success" >> print (v::Integer)
And Plug.hs:
module Plug (thing) where
thing :: Integer
thing = 1234000
I compile Plug with ghc -c Plug.hs
which produces Plug.o. I then compile Main.hs with ghc -o Main Main.hs
, and run Main. I also try replacing load
with dynload
, and running with runhaskell
. Only one of these four combinations works. What am I doing wrong?
- with
dynload
- compiled → prints "Loaded", then seg faults
- runhaskell → prints "Loading", then "Main.hs: Prelude.undefined"
- with
load
- compiled → successful, prints the Integer
- runhaskell → prints "Loading", hangs for 5-10 seconds, disappears
I'm on Mac OS X. GHC version 7.0.2. What am I doing wrong?
thanks,
Rob
Update
I can fix the compiled dynload
by changing Plug.hs to the following...
module Plug (thing) where
import Data.Dynamic
thing :: Dynamic
thing = toDyn (1234000::Integer)
It would be nice if it didn't seg fault on error. I guess it doesn't have enough meta data in Plug.o to check the type. Anyway, that leaves the runhaskell
cases. I filed a bug for those.
I've tried your example under Ubuntu 10.10 with GHC 6.12.1 and the results are: both dynload
and load
with running both complied or through runhaskell
gives me "Prelude.undefined" error, so I think you should report a bug to the developers.
I cannot see any special cases nor conditions in their module's haddock documentation, so I don't think you doing anything wrong.
这篇关于帮助Haskell动态插件加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!