X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FList.lhs;h=fe6750280c0df805164884ab22c9d5d59d0e1622;hb=69b0e13fc8f0a3f4c1e18e8176d3eead86ad9d83;hp=5dcf7e0ae48ba486c9d595ccce352dc7b2317ddc;hpb=d6403a02588eb91ad9342ff632a2d31966ae4287;p=ghc-base.git diff --git a/GHC/List.lhs b/GHC/List.lhs index 5dcf7e0..fe67502 100644 --- a/GHC/List.lhs +++ b/GHC/List.lhs @@ -108,7 +108,7 @@ null :: [a] -> Bool null [] = True null (_:_) = False --- | 'length' returns the length of a finite list as an 'Int'. +-- | /O(n)/. 'length' returns the length of a finite list as an 'Int'. -- It is an instance of the more general 'Data.List.genericLength', -- the result type of which may be any kind of number. length :: [a] -> Int @@ -503,11 +503,15 @@ or (x:xs) = x || or xs #endif -- | Applied to a predicate and a list, 'any' determines if any element --- of the list satisfies the predicate. +-- of the list satisfies the predicate. For the result to be +-- 'False', the list must be finite; 'True', however, results from a 'True' +-- value for the predicate applied to an element at a finite index of a finite or infinite list. any :: (a -> Bool) -> [a] -> Bool -- | Applied to a predicate and a list, 'all' determines if all elements --- of the list satisfy the predicate. +-- of the list satisfy the predicate. For the result to be +-- 'True', the list must be finite; 'False', however, results from a 'False' +-- value for the predicate applied to an element at a finite index of a finite or infinite list. all :: (a -> Bool) -> [a] -> Bool #ifdef USE_REPORT_PRELUDE any p = or . map p @@ -527,7 +531,8 @@ all p (x:xs) = p x && all p xs #endif -- | 'elem' is the list membership predicate, usually written in infix form, --- e.g., @x \`elem\` xs@. +-- e.g., @x \`elem\` xs@. For the result to be +-- 'False', the list must be finite; 'True', however, results from an element equal to @x@ found at a finite index of a finite or infinite list. elem :: (Eq a) => a -> [a] -> Bool -- | 'notElem' is the negation of 'elem'. @@ -647,7 +652,7 @@ zip _ _ = [] {-# INLINE [0] zipFB #-} zipFB :: ((a, b) -> c -> d) -> a -> b -> c -> d -zipFB c x y r = (x,y) `c` r +zipFB c = \x y r -> (x,y) `c` r {-# RULES "zip" [~1] forall xs ys. zip xs ys = build (\c n -> foldr2 (zipFB c) n xs ys) @@ -680,9 +685,11 @@ zipWith :: (a->b->c) -> [a]->[b]->[c] zipWith f (a:as) (b:bs) = f a b : zipWith f as bs zipWith _ _ _ = [] +-- zipWithFB must have arity 2 since it gets two arguments in the "zipWith" +-- rule; it might not get inlined otherwise {-# INLINE [0] zipWithFB #-} zipWithFB :: (a -> b -> c) -> (d -> e -> a) -> d -> e -> b -> c -zipWithFB c f x y r = (x `f` y) `c` r +zipWithFB c f = \x y r -> (x `f` y) `c` r {-# RULES "zipWith" [~1] forall f xs ys. zipWith f xs ys = build (\c n -> foldr2 (zipWithFB c f) n xs ys)