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