Commit 9f1b4646 authored by simonpj's avatar simonpj
Browse files

[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.
parent 207fd30f
...@@ -168,12 +168,30 @@ scanr1 _ [] = errorEmptyList "scanr1" ...@@ -168,12 +168,30 @@ scanr1 _ [] = errorEmptyList "scanr1"
-- iterate f x returns an infinite list of repeated applications of f to x: -- iterate f x returns an infinite list of repeated applications of f to x:
-- iterate f x == [x, f x, f (f x), ...] -- iterate f x == [x, f x, f (f x), ...]
iterate :: (a -> a) -> a -> [a] iterate :: (a -> a) -> a -> [a]
iterate f x = x : iterate f (f x) {-# 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 x is an infinite list, with x the value of every element.
repeat :: a -> [a] repeat :: a -> [a]
repeat x = xs where xs = x:xs {-# 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 n x is a list of length n with x the value of every element
replicate :: Int -> a -> [a] replicate :: Int -> a -> [a]
...@@ -347,9 +365,9 @@ all _ [] = True ...@@ -347,9 +365,9 @@ all _ [] = True
all p (x:xs) = p x && all p xs all p (x:xs) = p x && all p xs
{-# RULES {-# RULES
"any/build" forall p, g::forall b.(a->b->b)->b->b . "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/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 #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment