BSD-3-Clause licensed by Claude Heiland-Allen
Maintained by [email protected]
This version can be pinned in stack with:hgmp-0.1.1@sha256:c2ac5b5d01676fef8c143cbeb01a1ccc2ec81f1f65d03efc55a9beec3f5e5d7c,2339

Module documentation for 0.1.1

Used by 1 package in nightly-2019-01-07(full list with versions):


Haskell interface to GMP. Types and instances, and marshalling between Integer and Rational and the corresponding GMP types, along with raw foreign imports of GMP functions. Allows FFI to GMP code (whether in GMP itself or in third-party code that uses GMP).

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 Numeric.GMP.Raw.Safe (mpz_nextprime)
import System.IO.Unsafe (unsafePerformIO)

nextPrime :: Integer -> Integer
nextPrime n =
  unsafePerformIO $
    withOutInteger_ $ \rop ->
      withInInteger n $ \op ->
        mpz_nextprime rop op



  • raw function foreign import bindings
  • define hsc2hs #alignment macro for older GHC versions

  • use hsc2hs’s #alignment macro in Storable instances

  • initial release