[Haskell] big integer in haskell
ting wang
tting.wang at gmail.com
Fri Apr 15 19:03:22 EDT 2005
Hello all,
I am a new learner, and i am trying to write a function to calculate
factorial of a natural number:
(I use ghc 6.4, window xp)
fac :: Int -> Int
fac n
| n == 0 = 1
| n > 0 = fac (n-1) * n
| otherwise = 0
this works when n < 14 and result is 1278945280, when n > 14 the answer
is not right n = 15 result is 2004310016. I know it is maybe because of
overflow. So i calclate 2^32, 2^64, 2^128 the result correct and is much
bigger as 14!,Why? 2^n use some big integer or my implementation of n!
is not correct, I'm really confused.
Someone can help me?
Thanks
Ting Wang
More information about the Haskell
mailing list