RFC: ghc's dynamic linker

Andre Pang ozone@algorithm.com.au
Wed, 28 Aug 2002 16:05:41 +1000

On Tue, Aug 27, 2002 at 04:57:15 +0100, Duncan Coutts wrote:

> Alastair Reid <alastair@reid-consulting-uk.ltd.uk> wrote:
> > > People want to write programs using Haskell as an extension
> > > language.  Think of a plugin system or an embeded language. This is
> > > currently possible with ghc but requires some cunning hacks and
> > > fiddling with the linker and it has some limiations.
> > > [...]
> > 
> > It seems like what you're asking for is partly covered by the
> > foreign function interface specification
> I'd really like to do it without using the ffi. It would be possible to
> use a C interface between the main program and the extension modules but
> this would make it much harder to use and restricts the way data and
> control is passed between the modules.

I'm currently using the FFI, but I'm (ab)using the FFI in such
a way that it's possible to pass back any types you wish to the
calling program.

So a host program can actually load any function in a plugin
module, which the FFI doesn't normally allow.  The best thing is
that you can load a function of type Dynamic, and then coerce
that back to whatever type the function was originally -- which
means that you even get some type-checking done.

(The chiba/runtime_loader/RuntimeLoader.hs file does all this
 right now; check out the files in tests/ChibaTest0.hs).

If people are interested, I can package up a very small demo of
all the runtime loading stuff separately from the rest of my
project, so you guys can check it out without being confused by
the code which actually does useful stuff ;-).

> The thing is I'm not really linking to foriegn code, I'm just linking a
> Haskell program on the fly rather than statically. If this were to be
> done through the ffi perhaps it would be an extra language-dependant
> target - Haskell! Actually this might be a good approach for a

Or maybe the "Haskell" language-dependent target should be "GHC"
(which then allows you to load modules compiled by other Haskell
systems, like nhc).  Sounds like a good idea, although I have no
idea what's involved in implementing that sort of things :).

#ozone/algorithm <ozone@algorithm.com.au>          - trust.in.love.to.save