haskell - ghc 7.4.2, Dynamically calling modules -
i trying load , execute module dynamically,
below code
testmodule.hs
module testmodule evaluate = "hello !!!"
invoke.hs
module invoke import ghc import dynflags import ghc.paths (libdir) import unsafe.coerce (unsafecoerce) import data.dynamic execfnghc :: string -> string -> ghc execfnghc modname fn = mod <- findmodule (mkmodulename modname) nothing --setcontext [iimodule mod] ghc.setcontext [ ghc.iidecl $ (ghc.simpleimportdecl . ghc.mkmodulename $ modname) {ghc.ideclqualified = true} ] value <- compileexpr (modname ++ "." ++ fn) let value' = (unsafecoerce value) :: return value'
main2.hs
import ghc.paths (libdir) import ghc import invoke -- import testmodule main :: io () main = runghc (just libdir) $ str <- execfnghc "testmodule" "evaluate" return str
when try run program show me below error
[root@vps mypproj]# ./main2 main2: <command line>: module not loaded: `testmodule' (./testmodule.hs)
not sure missing, can please me resolve error
my thought problem has path,and program silently errors when can't load "testmodule," complains module not loaded. have tried using execfnghc module loaded, , have tried loading module in ghc naturally, such text.parsec, executing in it?
i'd test myself, don't see ghc.paths library anywhere :/.
Comments
Post a Comment