The hgmp package

[Tags:bsd3, library, test]

Currently, types and instances, and marshalling between Integer and Rational and the corresponding GMP types. That is, enough to allow FFI to GMP code (whether in GMP itself or in third-party code that uses GMP).

Supports only GHC with integer-gmp, this might change if there's any demand.

[Skip to Readme]


Change log
Dependencies base (>=4.8 && <4.10), ghc-prim (>=0.4 && <0.6), integer-gmp (==1.0.*) [details]
License BSD3
Copyright 2016 Claude Heiland-Allen
Author Claude Heiland-Allen
Category Numeric
Home page
Source repository head: git clone
this: git clone v0.1.0.1)
Uploaded Wed Aug 10 04:39:21 UTC 2016 by ClaudeHeilandAllen
Distributions NixOS:
Downloads 87 total (8 in the last 30 days)
0 []
Status Docs available [build log]
Last success reported on 2016-08-10 [all 1 reports]
Hackage Matrix CI




Maintainer's Corner

For package maintainers and hackage trustees

Readme for hgmp

Readme for hgmp-


Haskell interface to GMP. 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