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:[EMAIL PROTECTED]] 
| Sent: 02 November 2001 14:32
| To: [EMAIL PROTECTED]
| 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 
| [EMAIL PROTECTED] 
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-bugs
| 

_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to