[Haskell-cafe] Making extra GMP bindings

Robin Morisset robin.morisset at ens.fr
Thu Jul 26 12:20:47 CEST 2012


We haven't found mpz_nextprime in the list of gmp functions that have 
bindings in integer-gmp, and we would like to call it from a Haskell 

We have first looked at a few simple examples of using the FFI but found 
several difficulties:
- The mapping between Integer and the C data types isn't explicited 
- The gmp function gives its result by writing it in its second 
argument, instead of returning it.
   Building a wrapper for it that allocates the resulting Integer 
wouldn't be trivial because of how it could interact with the GC

Then we looked at how integer-gmp itself does it, it seems to be writing 
lots of cmm wrappers that call inside of the GHC runtime.

Is there an easier way to build a binding for a gmp function than to 
hack integer-gmp and recompile ghc ?

Robin Morisset & Florian Bourse

More information about the Haskell-Cafe mailing list