#1997: Stricter enumFrom instance for Integer, to match Int
-------------------------------+--------------------------------------------
    Reporter:  dons            |       Owner:          
        Type:  proposal        |      Status:  new     
    Priority:  normal          |   Milestone:  Not GHC 
   Component:  libraries/base  |     Version:  6.8.2   
    Severity:  normal          |    Keywords:          
  Difficulty:  Easy (1 hr)     |    Testcase:          
Architecture:  Multiple        |          Os:  Multiple
-------------------------------+--------------------------------------------
 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
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1997>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to