[Haskell-cafe] loading an Haskell symbol at run-time

Donald Bruce Stewart dons at cse.unsw.edu.au
Wed Jun 27 05:02:40 EDT 2007

> On Wednesday 27 June 2007 03:06:15 Donald Bruce Stewart wrote:
> > tittoassini:
> > > Hi,
> > >
> > > to load an Haskell symbol at run-time is still necessary to use the load
> > > functions from the hs-plugins library (System.Plugins.Load) or is there
> > > some function in the GHC API that does the same job?
> >
> > yes, definitely possible. i think Lemmih put an example on the wiki a
> > while ago. basically, ghc-api exposes the lower level api also used by
> > hs-plugins -- a nice project would be to provide the hs-plugins api
> > directly in ghc-api - avoiding the need for an external hs-plugins package.
> >
> > -- Don
> Hi Don, thanks for the answer.
> I checked again the http://haskell.org/haskellwiki/GHC/As_a_library page on 
> the wiki and there are examples of interactive evaluation but I cannot find 
> an example of loading a symbol from a compiled module.

Yes, this is the part I meant about duplicating the hs-plugins API. Both
ghc-apii and hs-plugins use the following api from the runtime:

    foreign import ccall unsafe "Linker.h lookupSymbol"
       pluginSym :: CString -> IO (Ptr a)

    foreign import ccall unsafe "Linker.h loadObj"
       pluginLoad :: CString -> IO Bool

    foreign import ccall unsafe "Linker.h initLinker"
       pluginInit :: IO ()

    foreign import ccall unsafe "Linker.h resolveObjs"
       pluginResolve :: IO Bool

hs-plugins duplicates some of the ghci internals to find, resolve and load
packages and objects, and access their symbols. So that code must exist in the
ghci parts of the ghc-api. You'll have to peek around in there.

-- Don

More information about the Haskell-Cafe mailing list