Add a more efficient Data.List.foldl' for GHC (from GHC's utils/Util.lhs)
authorIan Lynagh <igloo@earth.li>
Fri, 6 Jul 2007 20:55:26 +0000 (20:55 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 6 Jul 2007 20:55:26 +0000 (20:55 +0000)
Data/List.hs

index b6a847b..32013e9 100644 (file)
@@ -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,