Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The canonical way of is this:</p> <ol> <li>Export the functions (via FFI) to initialise RTS (runtime system) by the foreign program</li> <li>Export actual functions you would like to implement in Haskell</li> </ol> <p>The following sections of manual describe this: <a href="http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/ffi-ghc.html#ffi-library" rel="nofollow">[1]</a> <a href="http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/using-shared-libs.html#id471899" rel="nofollow">[2]</a></p> <p>On the other way, you can try technique described in this blog post (which mine, by the way):</p> <p><a href="http://mostlycode.wordpress.com/2010/01/03/shared-haskell-so-library-with-ghc-6-10-4-and-cabal/" rel="nofollow">http://mostlycode.wordpress.com/2010/01/03/shared-haskell-so-library-with-ghc-6-10-4-and-cabal/</a></p> <p>It boils down to creating a small C file which is called automatically right after a library is loaded. It should be linked together into the library.</p> <pre><code>#define CAT(a,b) XCAT(a,b) #define XCAT(a,b) a ## b #define STR(a) XSTR(a) #define XSTR(a) #a #include extern void CAT (__stginit_, MODULE) (void); static void library_init (void) __attribute__ ((constructor)); static void library_init (void) { /* This seems to be a no-op, but it makes the GHCRTS envvar work. */ static char *argv[] = { STR (MODULE) ".so", 0 }, **argv_ = argv; static int argc = 1; hs_init (&amp;argc, &amp;argv_); hs_add_root (CAT (__stginit_, MODULE)); } static void library_exit (void) __attribute__ ((destructor)); static void library_exit (void) { hs_exit (); } </code></pre> <p>Edit: Original blog post describing this technique is this: <a href="http://weblog.haskell.cz/pivnik/building-a-shared-library-in-haskell/" rel="nofollow">http://weblog.haskell.cz/pivnik/building-a-shared-library-in-haskell/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload