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:[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
>



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

Reply via email to