From: Ian Lynagh Date: Fri, 6 Jul 2007 20:55:26 +0000 (+0000) Subject: Add a more efficient Data.List.foldl' for GHC (from GHC's utils/Util.lhs) X-Git-Tag: 2007-09-13~50 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=54645a42daaafaf115ca10ae055edea5c1621a3e;p=ghc-base.git Add a more efficient Data.List.foldl' for GHC (from GHC's utils/Util.lhs) --- diff --git a/Data/List.hs b/Data/List.hs index b6a847b..32013e9 100644 --- a/Data/List.hs +++ b/Data/List.hs @@ -871,8 +871,14 @@ unfoldr f b = -- | A strict version of 'foldl'. foldl' :: (a -> b -> a) -> a -> [b] -> a +#ifdef __GLASGOW_HASKELL__ +foldl' f z xs = lgo z xs + where lgo z [] = z + lgo z (x:xs) = let z' = f z x in z' `seq` lgo z' xs +#else foldl' f a [] = a foldl' f a (x:xs) = let a' = f a x in a' `seq` foldl' f a' xs +#endif #ifdef __GLASGOW_HASKELL__ -- | 'foldl1' is a variant of 'foldl' that has no starting value argument,