File: README.md

package info (click to toggle)
haskell-hgmp 0.1.2.1-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: haskell: 913; ansic: 16; makefile: 6
file content (24 lines) | stat: -rwxr-xr-x 803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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