[Haskell-cafe] ANNOUNCE: metaplug

mad.one at gmail.com mad.one at gmail.com
Wed Oct 10 22:50:41 EDT 2007


Hi,

Recently I just decided to finish up and publish my library, metaplug:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/metaplug

What is it? It's basically a very tiny GHC API wrapper for programs that want eval and plugin style
functionality packaged in a basic library. The need for it spawned out of my GHC API investigations,
and looking at it as an easy way to get pluggable apps across GHC releases (hs-plugins is somewhat fragile
as it can break basically inbetween any release,) and with the oh-so-close ghc 6.8 release, I needed something
for things like my IRC bot (which does hot-code swapping) that wanted plugin style facilities without the
hassle of using the API explicitly or having dependencies on soon to break packages like hs-plugins.

Right now, there is no haddock documentation (I'll add it and upload a new version when I have time) but it's
simple enough to figure out how to use from the source code. Here's a quickie review:

Metaplug:            top level module, you only need import this
Metaplug.Eval:       exports one function, eval, which, well, does what it sounds like
Metaplug.Initialize: exports two functions, initSession and initSession' which initialize
                     a metaplug session. initSession' is for the case where you want to
                     provide your own very customized DynFlags to GHC.newSession
Metaplug.Loader:     provides two functions, loadFiles and compileCall which load files
                     into a session and compiles a dynamic to a function you can call.
Metaplug.Types:      simply provides the SessionMode and MetaSession types
Metaplug.Packages:   provides a very simple interface to query the package database for info,
                     please note this has NOT been tested with Cabal 1.2.0
                     
There're some example applications in the tests/ directory which show off how to use most of this stuff
in a very simple manner. Check the README.

There is one limitation to this, however. compileCall expects to compile a dynamic via GHC.dynCompileExpr;
what this means is your resource must be monomorphic (for Typeable to work.) As of right now, the easiest
way I can see to get around this is to simply define a datatype like such:

data Plugin {
 rsrc :: ... -- your type here
} deriving Typeable

And then have the symbol you want to compile could be for example,

plugin = Plugin { rsrc = dynmain }

The application in tests/dynst/ provides a good example of this. If anybody knows a way around this or
an easier way to approach it, I appreciate all feedback (unsafeCoerce# is an option but there's not a version
of compileCall to support this as of right now. I might add it if it seems needed.)

Any feedback appreciated.

Thanks,
Austin


More information about the Haskell-Cafe mailing list