[GHC] #1219: RULE for take is too strict

GHC trac at galois.com
Tue Mar 13 06:31:14 EDT 2007


#1219: RULE for take is too strict
-------------------------------+--------------------------------------------
    Reporter:  simonpj         |       Owner:  simonmar
        Type:  bug             |      Status:  new     
    Priority:  normal          |   Milestone:  6.6.1   
   Component:  libraries/base  |     Version:  6.6     
    Severity:  normal          |    Keywords:          
  Difficulty:  Easy (1 hr)     |    Testcase:          
Architecture:  Unknown         |          Os:  Unknown 
-------------------------------+--------------------------------------------
{{{
 main = print (map (const 'x') (take 1 (undefined:undefined)))
 }}}
 In ghci, or with ghc -O0, this produces `"x"`. With ghc -O, this produces
 `Prelude.undefined`.  Kirsten Chevalier found that the culprit is the
 RULE:
 {{{
 "take"     [~1] forall n xs . take n xs
     = case n of I# n# -> build (\c nil -> foldr (takeFB c nil)
                                                 (takeConst nil) xs n#)
 }}}
 This rule makes `take` strict in `xs`, but it should be lazy when `n`=0.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1219>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list