[Haskell-cafe] status of dynamic loading
qdunkan at gmail.com
Tue May 20 18:34:07 EDT 2008
I have an application where I'd like to load and run code at runtime.
As far as I know, the possibilities are:
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. I gather Austin Seipp has been doing some work
on this. Is there a newer version that should work? An easy fix for
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.
lambdabot also appears to have its own dynamic loading mechanism, I
haven't looked at the source enough yet to understand what it's doing.
Maybe there's some documentation out there.
The low-tech solution, used by xmonad, would be to pass the "dynamic"
code to main and just recompile the app for each instance, passing in
an instance specific set of config arguments. Of course, this isn't
really dynamic at all, and compiling all the various instances could
be clunky and awkward, but I know it works and could possibly be
reasonable if I also write my own little language for the stuff that
really has to be dynamic (anyone got one of these? lisplike would be
easy and ok, an haskell subset might be nicer... I would like to
avoid having *two* languages to write extensions in).
The last solution I can think of is to export an RPC API instead of
dynamically loading code. The difficulty here is coming up with a
vocabulary that can be flattened and shipped to another program
without becoming an excessive maintenance issue or being too
All in all, the dynamic loading approach of hs-plugins seems like the
easiest and most flexible, provided I can get its staged type
checking. Before I go trying to hack hs-plugins into working, or
poking around inside yi or lambdabot, can anyone point me at some
documentation, resources, advice, etc.?
More information about the Haskell-Cafe