[Haskell-cafe] Re: Haskell and scripting

Limestraël limestrael at gmail.com
Fri May 7 19:51:09 EDT 2010


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?

2010/5/8 Brandon S. Allbery KF8NH <allbery at ece.cmu.edu>

> On May 4, 2010, at 01:52 , Maciej Piechotka wrote:
>
>> 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).
>>
>
>
> 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.
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university    KF8NH
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100507/b347575a/attachment.html


More information about the Haskell-Cafe mailing list