[Haskell-cafe] Re: Export Haskell Libraries

Simon Marlow simonmarhaskell at gmail.com
Tue Apr 17 08:19:51 EDT 2007

Dan Weston wrote:
> In the GHC docs:
> http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/sec-ffi-ghc.html#using-own-main 
> "There can be multiple calls to hs_init(), but each one should be 
> matched by one (and only one) call to hs_exit()[8]."
> What exactly happens with nested calls? Is there only one runtime 
> created, with a simple counter to know which hs_exit should shut it 
> down?

Yes.  But the runtime doesn't currently support restarting (hs_exit() followed 
by hs_init()).

> If so, is there a way of having multiple interpreters open safely 
> at the same time?

I'm not sure exactly what you mean by "multiple interpreters".  The runtime is 
only designed to support a single instance of itself (it uses global static 
storage everywhere).

> Or does each hs_init() create a new separate concurrent runtime (the 
> preferable alternative)?

Nope, see above.  To do that you'd need a "runtime handle" returned by hs_init() 
and passed to every foreign exported function, somehow.

> And what is the cost of creating and destructing the GHC runtime anyway?

Not much.

> Can the Haskell interpreter be in a Linux shared-object library, so long 
> as I make sure to call hs_init() after loading and hs_exit() before 
> unloading it? My experiments so far show this working flawlessly, but I 
> vaguely remember an e-mail thread saying GHC couldn't be linked in 
> dynamically.

Perhaps, although the shared library won't really be shared - it'll be linked in 
place each time you use it, because we don't currently have support for PIC 
everywhere (well, we have partial support and there's a SoC project to finish it 


More information about the Haskell-Cafe mailing list