Stack overflow
Simon Peyton-Jones
simonpj at microsoft.com
Fri Nov 2 12:36:05 EST 2001
Yes, I agree with this, and I'd already snuck it into the
rewrite of the Enum section that I had to do anyhow.
Would you like to read the section (6.3.4) and see if
you think it is better specified now?
Simon
| -----Original Message-----
| From: Josef Svenningsson [mailto:josefs at cs.chalmers.se]
| Sent: 02 November 2001 15:54
| To: Simon Peyton-Jones
| Cc: Ian Lynagh; glasgow-haskell-bugs at haskell.org
| Subject: RE: Stack overflow
|
|
| Hi!
|
| OK, so the Int instance for Enum is a bit naughty in that
| [bottom..] is bottom. But then one can argue that all
| instances of Enum should be naughty in this respect. The
| argument is as follows and uses the default declaration of
| enumFrom in the Enum class (I've added some types with the
| intention to clarify a bit what's happening):
|
| [bottom..] :: [Integer]
| = { Syntactic sugar, section 3.10 }
| enumFrom bottom :: [Integer]
| = { Using the default definition of enumFrom in the Enum
| class } map toEnum ([fromEnum bottom ..] :: [Int]) = {
| fromEnum is strict } map toEnum ([bottom..] :: [Int]) = {
| according to Simon } map toEnum (bottom :: [Int]) = { map is
| strict in it's second argument } bottom
|
| Note that I've assumed that fromEnum is strict. I'd say this
| is a pretty reasonable assumption.
|
| The key thing here is that the Report assumes that there is
| an instance Enum Int which it uses in the default
| declarations. One could wish that the report gave some more
| detail about the Int instance of Enum at least. Then one
| could use that to derive the behavour of the other instances,
| using the default definitions like I did above.
|
| The bottom (:-) line, from how I interpret the Report, is
| that the instances of Int and Integer should at least have
| the same behaviour in this respect. But exactly how they
| should behave is up to the implementor. I'd vote for the
| strict version.
|
| Cheers,
|
| /Josef
|
|
| On Fri, 2 Nov 2001, Simon Peyton-Jones wrote:
|
| > 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
| > |
| >
| > _______________________________________________
| > Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs at haskell.org
| > http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
| >
|
|
|
| _______________________________________________
| 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