[Haskell-cafe] [Haskell] Silent error
Henning Thielemann
lemming at henning-thielemann.de
Mon Jan 21 00:27:47 CET 2013
On Mon, 21 Jan 2013, miphis at meta.ua wrote:
> The program looks like this:
>
> --***********************
> factorial :: Int->Int
> factorial n = product [1..n]
>
> main = do
> print $ factorial 50
> --***********************
>
> And that yields "0" (no errors). Is it a bug or feature? :)
This question is certainly better posted to haskell-cafe.
The answer is: Int has limited bitsize (32 ord 64 bit depending on your
machine), thus it computes factorial modulo 2^32 or 2^64. You can get the
correct result by replacing Int by Integer.
More information about the Haskell-Cafe
mailing list