[Haskell-cafe] faster factorial function via FFI?

Bryan O'Sullivan bos at serpentine.com
Tue Apr 24 13:33:06 EDT 2007

Dan Weston wrote:
> A thing of beauty is a joy forever. Simple, fast, elegant.

>> factorial :: Integer -> Integer
>> factorial = product . zipWith (^) . factorisedFactorial

Well... The zipWith (^) should be map (uncurry (^)).

And the performance of this approach is strongly dependent on the 
efficiency of your prime sieve, so you're moving the complexity around, 
not eliminating it.

The binary splitting method doesn't need a source of primes, and 
performs half decently on numbers such as fact 1e6 (5.5 million digits 
computed in about 5 seconds).


More information about the Haskell-Cafe mailing list