Stricter enumFrom instance for Integer, to match Int
A common source of user complaints are code like the following failing:
main = print (head (drop 1000000 [1 .. ]))
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize' to increase it.
Urgh!
Due to a lazy accumulator in enumFrom for Integer. While the following are all fine:
main = print (head (drop 1000000 [1 .. 100000000000000]))
(enumFromTo is strict enough on Integer), and:
main = print (head (drop 1000000 [(1::Int) .. ]))
(Int has had a strict accumulator for enumFrom since 1994.)
"Atomic" strictness on Num operations for Int is fairly consistent through the base libraries (e.g. length, take, maximum), however for Integer it is ad hoc. maximum, for example, has a strict instance for Integer, but as we see here, enumFrom is still so lazy it fails.
This patch adds a strict accumulator to Integer's enumFrom, and makes the suggestion we in future ensure Num operations on Integer in the base library behave as strict as Int instances.
-enumDeltaInteger x d = x : enumDeltaInteger (x+d) d
+enumDeltaInteger x d = x `seq` x : enumDeltaInteger (x+d) d
Trac metadata
Trac field | Value |
---|---|
Version | 6.8.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | dons@galois.com |
Operating system | Multiple |
Architecture | Multiple |