There is the package hint, which embeds the calls to GHC API.
Quite easy to use:
Let's say your configuration file (cfg/Script.hs) contains a function "script" that you want to get:
type ScriptFun = IO ()
loadScript :: IO ScriptFun
loadScript = do
liftM (either (error . show) id) $ runInterpreter $ do
path <- get searchPath
set [searchPath := ("./cfg":path)]
loadModules ["Script"]
setTopLevelModules ["Script"]
exports <- getModuleExports "Script"
if Fun "script" `elem` exports
then interpret "script" (as :: ScriptFun)
else error "script function not found"
There is just the line I put in bold that bothers me. Can't we get the action "script" more easily than by re-interpreting some code?
On May 4, 2010, at 01:52 , Maciej Piechotka wrote:On the one hand, this is doable with the GHC API. On the other, that more or less means your program contains what amounts to a full copy of GHC.
After change of file you have to wait a long time as it compiles and
links with yi. On my system (1 GB of RAM taken by system + 1 GB 'free' +
2 GB swaps, x86-64) it could in some situations it caused OOM. I'd
prefer if the code was interpreted by ghci instead of compiled by GHC in
this case (it should be as fast as most of the code was compiled
anyway).
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe