@hackage hgmp0.1.2.1
Haskell interface to GMP
Categories
License
BSD-3-Clause
Maintainer
claude@mathr.co.uk
Links
Versions
Installation
Dependencies (4)
- base >=4.8 && <4.23
- ghc-bignum >=1.0 && <1.5
- ghc-prim >=0.4 && <0.14
- integer-gmp >=1.0 && <1.1 Show all…
Dependents (7)
@hackage/hMPC, @hackage/cryptol, @hackage/rounded, @hackage/acme-everything, @hackage/fast-arithmetic, @hackage/fplll, Show all…
hgmp
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