[Haskell-cafe] [ANN] hgmp-0.1.0.0

Claude Heiland-Allen claude at mathr.co.uk
Mon Aug 1 20:48:17 UTC 2016


Hi Sergey, café,

On 01/08/16 21:13, Sergey Bushnyak wrote:
> Nice work! How it differs from
> https://hackage.haskell.org/package/integer-gmp ?

Good question!

integer-gmp is a binding of enough of GMP to make implementing Integer 
possible.  It is very low level in the GHC package heirarchy, so trying 
to make it provide high level code is painful, if not impossible.  It 
exposes the bare minimum of functionality to let most of Integer be 
implemented by the base package.

hgmp uses the public integer-gmp internal details (also ghc-prim for the 
lower level stuff like copying byte arrays to/from Haskell heap / 
foreign memory) to expose helpers using Integer and Rational for 
interacting with foreign code that expects mpz_t and mpq_t data structures.

So the package heirarchy is something like this diagram (fixed width 
font recommended):

        hgmp -- Integer and Rational FFI helpers for libgmp API
       / | \
      |  | base -- Integer numeric instances, the standard Prelude, etc
      |  |  | :
      | integer-gmp -- bindings for Integer implementation (bare minimum)
      |  |   /
     ghc-prim -- very low level compiler specifics

hgmp eventually should also contain bindings to the functions in GMP, 
I'm considering the best way to go about it.  My current thought is to 
generate raw and higher-level bindings semi-automatically from the C API 
header file gmp.h - any other suggestions?


Claude

> On 08/01/2016 10:57 PM, Claude Heiland-Allen wrote:
>> Hi all,
>>
>> hgmp 0.1.0.0 is released! [0]
>>
>> hgmp is a Haskell interface to GMP[1] (for GHC with the default
>> integer-gmp implementation of Integer). Contains type definitions and
>> marshalling functions, to be able to write FFI bindings using
>> Haskell's Integer and Rational types. Function bindings may come in a
>> future version.
>>
>> A simple example illustrating binding to GMP's next probable-prime
>> function:
>>
>>     {-# LANGUAGE ForeignFunctionInterface #-}
>>
>>     import Foreign.Ptr (Ptr(..))
>>     import Numeric.GMP.Types (MPZ)
>>     import Numeric.GMP.Utils (withInInteger, withOutInteger_)
>>     import System.IO.Unsafe (unsafePerformIO)
>>
>>     foreign import ccall safe "__gmpz_nextprime"
>>       mpz_nextprime :: Ptr MPZ -> Ptr MPZ -> IO ()
>>
>>     nextPrime :: Integer -> Integer
>>     nextPrime n =
>>       unsafePerformIO $
>>         withOutInteger_ $ \rop ->
>>           withInInteger n $ \op ->
>>             mpz_nextprime rop op
>>
>> You can cabal install (or otherwise get it) from Hackage[2], or get
>> (or browse[3]) the freshest sources from git:
>>
>>     git clone https://code.mathr.co.uk/hgmp.git
>>
>> Any and all feedback welcome! I'm sure there are some things that
>> could be improved, and ideas for future versions will be appreciated too.
>>
>> [0] https://mathr.co.uk/blog/2016-08-01_hgmp_0_1_0_0_released.html
>> [1] https://gmplib.org/
>> [2] http://hackage.haskell.org/package/hgmp
>> [3] https://code.mathr.co.uk/hgmp
>>
>> Thanks,
>>
>>
>> Claude
>

-- 
https://mathr.co.uk



More information about the Haskell-Cafe mailing list