module Numeric.Combinatorics ( choose
, doubleFactorial
, catalan
) 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 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)
doubleFactorial :: Int -> IO Integer
doubleFactorial = conjugateGMP double_factorial_ats