miphis | 21 Jan 00:17 2013
Picon

Silent error

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? :)

______________________________
Акция! Скидка до - 50% на колготы зимних коллекций в
Линии магазинов EVA!
http://go.meta.ua/eva_colgotes 

_______________________________________________
Haskell mailing list
Haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell
Henning Thielemann | 21 Jan 00:27 2013
Picon

Re: [Haskell] Silent error


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.

Gmane