[Haskell-cafe] status of dynamic loading

Austin Seipp mad.one at gmail.com
Tue May 20 19:40:04 EDT 2008

Excerpts from Evan Laforge's message of Tue May 20 17:34:07 -0500 2008:
> Use hs-plugins.  I'm not sure if this still works on modern ghc, or if
> it works on my platform (darwin intel), but I managed to get this
> compiled after "fixing" a use of STArray whose arity apparently
> changed, but I probably broke it because now I get "Error in array
> index" all the time. 

What version of GHC, and were are you pulling the hs-plugins code from?
If you're using at least 6.8 and you do:

darcs get http://code.haskell.org/~dons/code/hs-plugins

It should work just fine. Cale replaced a lot of the brittle parts
(interface file parsing) with supplements that use the GHC API, so it
should be at least a little easier to update, and last time I built it,
it installed and worked nicely (I have heard no word on whether it does
so for darwin/intel.)

If memory serves me, there was a version put on hackage a few weeks ago
from that repository that I would think work just as good.

> I gather Austin Seipp has been doing some work on this. 

Just playing around. ;)

> Then there's the ghc api, which I gather is seen as the way forward
> from hs-plugins, saving it from hi-parsing brittleness and platform
> specific breakage.  I think Yi uses this, apparently in in the Shim
> package.  I poked around some, but wasn't too clear to me what was
> going on, if I was looking in the right place, and if this is a
> reasonable way forward.

>From my experiences, getting the GHC API to work properly like I wanted
was a bit of a pain point. In many instances, if I just threw away the
session after changing the code and making a new session and reloading,
the old version is still apparently resides in memory and is still
executed. I spent a bit of time playing with this, etc. etc. but never
got it to fully work.

I did hear later that by simply setting the session you already used to
be empty and then compiling modules into it works like what you could get
from hs-plugins, though (a la load -> unload -> load or just call reload.)

If you still want to give the GHC API a try, I have a package that just
does some of the basic, quick stuff and it's on hackage:


It's not been updated for a long time though (since way before GHC 6.8.)
The code is really small and the changes should be trivial, though.

There is also hint which embeds GHC into your code and is a wrapper like
my metaplug package:


I haven't tried it, but it might be worth investigating if hs-plugins
doesn't turn to work out, and it looks far more well done than mine
(which was forged in a time of haskell-naivety, for the most part.)

"It was in the days of the rains that their prayers went up, 
not from the fingering of knotted prayer cords or the spinning 
of prayer wheels, but from the great pray-machine in the
monastery of Ratri, goddess of the Night."
 Roger Zelazny

More information about the Haskell-Cafe mailing list