From: simonmar Date: Tue, 2 Apr 2002 10:19:21 +0000 (+0000) Subject: [project @ 2002-04-02 10:19:21 by simonmar] X-Git-Tag: nhc98-1-18-release~1067 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=3430ea0ffbbcbde818c323c743fb8953cdcbf9f1;p=ghc-base.git [project @ 2002-04-02 10:19:21 by simonmar] Add foldl', the strict version of foldl. --- diff --git a/Data/List.hs b/Data/List.hs index 9082db5..ea2ff2a 100644 --- a/Data/List.hs +++ b/Data/List.hs @@ -9,7 +9,7 @@ -- Stability : provisional -- Portability : portable -- --- $Id: List.hs,v 1.2 2001/12/21 15:07:21 simonmar Exp $ +-- $Id: List.hs,v 1.3 2002/04/02 10:19:21 simonmar Exp $ -- -- Operations on lists. -- @@ -90,6 +90,7 @@ module Data.List , length -- :: [a] -> Int , (!!) -- :: [a] -> Int -> a , foldl -- :: (a -> b -> a) -> a -> [b] -> a + , foldl' -- :: (a -> b -> a) -> a -> [b] -> a , foldl1 -- :: (a -> a -> a) -> [a] -> a , scanl -- :: (a -> b -> a) -> a -> [b] -> [a] , scanl1 -- :: (a -> a -> a) -> [a] -> [a] @@ -521,6 +522,14 @@ unfoldr f b = Just (a,new_b) -> a : unfoldr f new_b Nothing -> [] + +-- ----------------------------------------------------------------------------- +-- strict version of foldl + +foldl' :: (a -> b -> a) -> a -> [b] -> a +foldl' f a [] = a +foldl' f a (x:xs) = let a' = f a x in a' `seq` foldl' f a' xs + -- ----------------------------------------------------------------------------- -- List sum and product