Stack overflow

Simon Peyton-Jones simonpj at microsoft.com
Fri Nov 2 10:10:29 EST 2001


The [1..] generates [1,1+1,1+1+1,1+1+1+1, ...]
Those thunks all go into the heap.  Then last grabs
the last one and evaluates it, so they all go on the 
stack. Result death.

The Int instance for Enum is a bit naughty in GHC:
it is strict.  That is [bottom..] is bottom rather than
being [bottom,bottom,bottom...].  (Actually the
Report is vague on this point; sigh.)

So the Int instance evaluates as it goes, while the
Integer instance does not.  Maybe we should
make the Integer instance strict too.

Simon



| -----Original Message-----
| From: Ian Lynagh [mailto:igloo at earth.li] 
| Sent: 02 November 2001 14:32
| To: glasgow-haskell-bugs at haskell.org
| Subject: Stack overflow
| 
| 
| 
| With
| 
| main = putStrLn $ show $ last $ zip [1..] (replicate 100000 'a')
| 
| I get
| 
| Stack space overflow: current size 1048576 bytes.
| Use `+RTS -Ksize' to increase it.
| 
| If I Change the [1..] to ([1..] :: [Int]) then it works fine.
| 
| 
| Ian
| 
| 
| _______________________________________________
| Glasgow-haskell-bugs mailing list 
| Glasgow-haskell-bugs at haskell.org 
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-bugs
| 




More information about the Glasgow-haskell-bugs mailing list