module Numeric.Combinatorics ( factorial
, choose
, doubleFactorial
) where
import Control.Composition
import Data.GMP
import Foreign.C
import Foreign.Ptr
import Foreign.Storable
foreign import ccall unsafe factorial_ats :: CInt -> Ptr GMPInt
foreign import ccall unsafe double_factorial_ats :: CInt -> Ptr GMPInt
foreign import ccall unsafe choose_ats :: CInt -> CInt -> Ptr GMPInt
choose :: Int -> Int -> IO Integer
choose = (gmpToInteger <=<) . (peek .* on choose_ats fromIntegral)
doubleFactorial :: Int -> IO Integer
doubleFactorial = conjugateGMP double_factorial_ats
factorial :: Int -> IO Integer
factorial = conjugateGMP factorial_ats