[Haskell-beginners] [Int] oddness with summing large lists

Philip Scott haskell-beginners at foo.me.uk
Thu Apr 29 18:17:05 EDT 2010


Hi ho,
> I can deduce that you have a 32-bit system (as I do).
> Because:
>
> Prelude>  1000000000000 :: Int
> -727379968
>
> So ([1 .. 1000000000000] :: [Int]) == [] and sum [] == 0 isn't surprising
> at all.
>
>    

Once again, your explanation makes perfect sense :)

>> And now the really odd part... take away one zero
>>
>> Prelude>  let d = [1..100000000000] :: [Int]
>>      
> Prelude>  100000000000 :: Int
> 1215752192
>
> , which is a pretty large number. Since you gave the list a name, it stays
> in memory. For each Int in the list, at least 3 machine words are needed
> (one for the Int, pointer from cons-cell to value, pointer to next cons-
> cell; actually, I think the overhead is larger), so if you have less than
> 14GB of RAM, your ghci can't do it.
>
>    

Fair enough, I don't think my laptop is quite up to that :)

Thanks for your help,

- Philip


More information about the Beginners mailing list