There is the package hint, which embeds the calls to GHC API.<br><br>Quite easy to use:<br>Let's say your configuration file (cfg/Script.hs) contains a function "script" that you want to get:<br><br>type ScriptFun = IO ()<br>
<br>loadScript :: IO ScriptFun<br>loadScript = do<br> liftM (either (error . show) id) $ runInterpreter $ do<br> path <- get searchPath<br> set [searchPath := ("./cfg":path)]<br> loadModules ["Script"]<br>
setTopLevelModules ["Script"]<br> exports <- getModuleExports "Script"<br> if Fun "script" `elem` exports<br> then <b>interpret "script" (as :: ScriptFun)</b><br> else error "script function not found"<br>
<br><br>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?<br><br><div class="gmail_quote">2010/5/8 Brandon S. Allbery KF8NH <span dir="ltr"><<a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On May 4, 2010, at 01:52 , Maciej Piechotka wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
After change of file you have to wait a long time as it compiles and<br>
links with yi. On my system (1 GB of RAM taken by system + 1 GB 'free' +<br>
2 GB swaps, x86-64) it could in some situations it caused OOM. I'd<br>
prefer if the code was interpreted by ghci instead of compiled by GHC in<br>
this case (it should be as fast as most of the code was compiled<br>
anyway).<br>
</blockquote>
<br>
<br></div>
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.<br><font color="#888888">
<br>
-- <br>
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] <a href="mailto:allbery@kf8nh.com" target="_blank">allbery@kf8nh.com</a><br>
system administrator [openafs,heimdal,too many hats] <a href="mailto:allbery@ece.cmu.edu" target="_blank">allbery@ece.cmu.edu</a><br>
electrical and computer engineering, carnegie mellon university KF8NH<br>
<br>
<br>
</font><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>