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

Philip Scott haskell-beginners at foo.me.uk
Wed Apr 28 17:46:11 EDT 2010


Hi Scott,

Thanks for the reply,

> I can't really do too much with it because I don't have any swap on
> this machine, but I definately don't get
> 0 for your first example.
>    
ghci quits rather ungracefully when I do that :)

It is a silly thing to be doing, granted - just wondering if what I saw 
was expected behavior. Perhaps it is the OS (Windows 7) killing the 
process for using to much memory - but I would've thought I would get a 
stack overflow before that happens.

Ho hum!

- Philip

> On Wed, Apr 28, 2010 at 4:32 PM, Philip Scott
> <haskell-beginners at foo.me.uk>  wrote:
>    
>> Hi all,
>>
>> I kind of stumbled into this while doing something else - but I thought it
>> was worth posting since I have never actually managed to crash ghci before
>> :)
>>
>> Prelude>  let d = [1..1000000000000] :: [Int]
>> Prelude>  sum d
>> 0
>>
>> 0?  I mean, I might have expected an integer overflow, but 0?
>>
>> And now the really odd part... take away one zero
>>
>> Prelude>  let d = [1..100000000000] :: [Int]
>> Prelude>  sum d
>> <  ghci crashes and quits>
>>
>> A slightly more reasonable number..
>>
>> Prelude>  let d = [1..10000000] :: [Int]
>> Prelude>  sum d
>> *** Exception: stack overflow
>>
>> At least I can appreciate what is going on in this one  :)
>>
>> I'm aware that this is a silly way to sum from 1 to n, but I am at a loss to
>> explain the above behavior (Except the stack overflow, that is fair enough).
>> I'm also aware that Int is a machine Int, not a clever infinite haskell Int.
>>
>> Any ideas?
>>
>> All the best,
>>
>> Phil
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>      
>    



More information about the Beginners mailing list