[commit: containers] master: Inline {Map, Set}.fold* when 2 arguments are given. (6c430a5)

Paolo Capriotti <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.libraries
Message-ID <[email protected]>
Repository : ssh://darcs.haskell.org//srv/darcs/packages/containers

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/6c430a5d7cb0bba29857b193729193217bcf048c

>---------------------------------------------------------------

commit 6c430a5d7cb0bba29857b193729193217bcf048c
Author: Milan Straka <[email protected]>
Date:   Sun Apr 22 18:00:43 2012 +0200

    Inline {Map,Set}.fold* when 2 arguments are given.
    
    Inlining folds when 2 arguments are given is consistent
    with Prelude.foldr and {IntMap,IntSeT}.fold*.

>---------------------------------------------------------------

 Data/Map/Base.hs |   16 ++++++++--------
 Data/Set.hs      |    8 ++++----
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Data/Map/Base.hs b/Data/Map/Base.hs
index 9669551..966cba7 100644
--- a/Data/Map/Base.hs
+++ b/Data/Map/Base.hs
@@ -1648,7 +1648,7 @@ mapKeysMonotonic f (Bin sz k x l r) =
 -- > let f a len = len + (length a)
 -- > foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
 foldr :: (a -> b -> b) -> b -> Map k a -> b
-foldr f = go
+foldr f z = go z
   where
     go z Tip             = z
     go z (Bin _ _ x l r) = go (f x (go z r)) l
@@ -1658,7 +1658,7 @@ foldr f = go
 -- evaluated before using the result in the next application. This
 -- function is strict in the starting value.
 foldr' :: (a -> b -> b) -> b -> Map k a -> b
-foldr' f = go
+foldr' f z = go z
   where
     STRICT_1_OF_2(go)
     go z Tip             = z
@@ -1675,7 +1675,7 @@ foldr' f = go
 -- > let f len a = len + (length a)
 -- > foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
 foldl :: (a -> b -> a) -> a -> Map k b -> a
-foldl f = go
+foldl f z = go z
   where
     go z Tip             = z
     go z (Bin _ _ x l r) = go (f (go z l) x) r
@@ -1685,7 +1685,7 @@ foldl f = go
 -- evaluated before using the result in the next application. This
 -- function is strict in the starting value.
 foldl' :: (a -> b -> a) -> a -> Map k b -> a
-foldl' f = go
+foldl' f z = go z
   where
     STRICT_1_OF_2(go)
     go z Tip             = z
@@ -1703,7 +1703,7 @@ foldl' f = go
 -- > let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
 -- > foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"
 foldrWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b
-foldrWithKey f = go
+foldrWithKey f z = go z
   where
     go z Tip             = z
     go z (Bin _ kx x l r) = go (f kx x (go z r)) l
@@ -1713,7 +1713,7 @@ foldrWithKey f = go
 -- evaluated before using the result in the next application. This
 -- function is strict in the starting value.
 foldrWithKey' :: (k -> a -> b -> b) -> b -> Map k a -> b
-foldrWithKey' f = go
+foldrWithKey' f z = go z
   where
     STRICT_1_OF_2(go)
     go z Tip              = z
@@ -1731,7 +1731,7 @@ foldrWithKey' f = go
 -- > let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
 -- > foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)"
 foldlWithKey :: (a -> k -> b -> a) -> a -> Map k b -> a
-foldlWithKey f = go
+foldlWithKey f z = go z
   where
     go z Tip              = z
     go z (Bin _ kx x l r) = go (f (go z l) kx x) r
@@ -1741,7 +1741,7 @@ foldlWithKey f = go
 -- evaluated before using the result in the next application. This
 -- function is strict in the starting value.
 foldlWithKey' :: (a -> k -> b -> a) -> a -> Map k b -> a
-foldlWithKey' f = go
+foldlWithKey' f z = go z
   where
     STRICT_1_OF_2(go)
     go z Tip              = z
diff --git a/Data/Set.hs b/Data/Set.hs
index a1c8599..1b208c9 100644
--- a/Data/Set.hs
+++ b/Data/Set.hs
@@ -606,7 +606,7 @@ fold = foldr
 --
 -- > toAscList set = foldr (:) [] set
 foldr :: (a -> b -> b) -> b -> Set a -> b
-foldr f = go
+foldr f z = go z
   where
     go z Tip           = z
     go z (Bin _ x l r) = go (f x (go z r)) l
@@ -616,7 +616,7 @@ foldr f = go
 -- evaluated before using the result in the next application. This
 -- function is strict in the starting value.
 foldr' :: (a -> b -> b) -> b -> Set a -> b
-foldr' f = go
+foldr' f z = go z
   where
     STRICT_1_OF_2(go)
     go z Tip           = z
@@ -630,7 +630,7 @@ foldr' f = go
 --
 -- > toDescList set = foldl (flip (:)) [] set
 foldl :: (a -> b -> a) -> a -> Set b -> a
-foldl f = go
+foldl f z = go z
   where
     go z Tip           = z
     go z (Bin _ x l r) = go (f (go z l) x) r
@@ -640,7 +640,7 @@ foldl f = go
 -- evaluated before using the result in the next application. This
 -- function is strict in the starting value.
 foldl' :: (a -> b -> a) -> a -> Set b -> a
-foldl' f = go
+foldl' f z = go z
   where
     STRICT_1_OF_2(go)
     go z Tip           = z
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.