[Haskell] Silent error

Gregory Collins greg at gregorycollins.net
Mon Jan 21 00:23:02 CET 2013


Integer overflow. factorial 50 mod 2^32 = 0.

Change "Int" to "Integer" to get the correct result
(30414093201713378043612608166064768844377641568960512000000000000).


On Mon, Jan 21, 2013 at 12:17 AM, <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? :)
>
> ______________________________
> Акция! Скидка до - 50% на колготы зимних коллекций в Линии магазинов EVA!
> http://go.meta.ua/eva_colgotes
>
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>



-- 
Gregory Collins <greg at gregorycollins.net>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell/attachments/20130121/4c5f853c/attachment.htm>


More information about the Haskell mailing list