From 9f1b46468fc197f371972b2c99528eed278cdd03 Mon Sep 17 00:00:00 2001 From: simonpj Date: Fri, 28 May 1999 19:18:52 +0000 Subject: [PATCH] [project @ 1999-05-28 19:18:52 by simonpj] Fix a killer bug in the RULES for 'all' and 'any' that simply made them wrong, with various obscure consequences. --- ghc/lib/std/PrelList.lhs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/ghc/lib/std/PrelList.lhs b/ghc/lib/std/PrelList.lhs index 2e4a076..c8b89ca 100644 --- a/ghc/lib/std/PrelList.lhs +++ b/ghc/lib/std/PrelList.lhs @@ -168,12 +168,30 @@ scanr1 _ [] = errorEmptyList "scanr1" -- iterate f x returns an infinite list of repeated applications of f to x: -- iterate f x == [x, f x, f (f x), ...] -iterate :: (a -> a) -> a -> [a] -iterate f x = x : iterate f (f x) +iterate :: (a -> a) -> a -> [a] +{-# INLINE iterate #-} +iterate f x = build (\c n -> iterateFB c f x) + +iterateFB c f x = x `c` iterateFB c f (f x) + +iterateList f x = x : iterateList f (f x) + +{-# RULES +"iterate" iterateFB (:) = iterateList + #-} + -- repeat x is an infinite list, with x the value of every element. -repeat :: a -> [a] -repeat x = xs where xs = x:xs +repeat :: a -> [a] +{-# INLINE repeat #-} +repeat x = build (\c n -> repeatFB c x) + +repeatFB c x = xs where xs = x `c` xs +repeatList x = xs where xs = x : xs + +{-# RULES +"repeat" repeatFB (:) = repeatList + #-} -- replicate n x is a list of length n with x the value of every element replicate :: Int -> a -> [a] @@ -347,9 +365,9 @@ all _ [] = True all p (x:xs) = p x && all p xs {-# RULES "any/build" forall p, g::forall b.(a->b->b)->b->b . - any p (build g) = g ((&&) . p) True + any p (build g) = g ((||) . p) False "all/build" forall p, g::forall b.(a->b->b)->b->b . - all p (build g) = g ((||) . p) False + all p (build g) = g ((&&) . p) True #-} #endif -- 1.7.10.4