Opened 11 years ago

Closed 10 years ago

Last modified 8 years ago

#1219 closed merge (fixed)

RULE for take is too strict

Reported by: simonpj Owned by: igloo
Priority: normal Milestone: 6.6.1
Component: libraries/base Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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.

Change History (5)

comment:1 Changed 10 years ago by simonmar

Owner: changed from simonmar to igloo
Type: bugmerge

Fixed, to merge in libraries/base:

Tue Mar 27 11:39:41 BST 2007  Simon Marlow <>
  * fix strictness of foldr/build rule for take, see #1219

and testsuite:

Tue Mar 27 11:38:51 BST 2007  Simon Marlow <>
  * add test for #1219

comment:2 Changed 10 years ago by igloo

Resolution: fixed
Status: newclosed


comment:3 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:4 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:5 Changed 8 years ago by simonmar

difficulty: Easy (1 hr)Easy (less than 1 hour)
Note: See TracTickets for help on using tickets.