projects
/
ghc-base.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
use '==' consistently rather than '->' in examples
[ghc-base.git]
/
Data
/
Foldable.hs
diff --git
a/Data/Foldable.hs
b/Data/Foldable.hs
index
ed05a16
..
c44f0cd
100644
(file)
--- a/
Data/Foldable.hs
+++ b/
Data/Foldable.hs
@@
-96,7
+96,12
@@
import Array
-- > foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r
--
-- This is suitable even for abstract types, as the monoid is assumed
-- > foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r
--
-- This is suitable even for abstract types, as the monoid is assumed
--- to satisfy the monoid laws.
+-- to satisfy the monoid laws. Alternatively, one could define @foldr@:
+--
+-- > instance Foldable Tree where
+-- > foldr f z Empty = z
+-- > foldr f z (Leaf x) = f x z
+-- > foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l
--
class Foldable t where
-- | Combine the elements of a structure using a monoid.
--
class Foldable t where
-- | Combine the elements of a structure using a monoid.
@@
-157,6
+162,9
@@
instance Foldable [] where
instance Ix i => Foldable (Array i) where
foldr f z = Prelude.foldr f z . elems
instance Ix i => Foldable (Array i) where
foldr f z = Prelude.foldr f z . elems
+ foldl f z = Prelude.foldl f z . elems
+ foldr1 f = Prelude.foldr1 f . elems
+ foldl1 f = Prelude.foldl1 f . elems
-- | Fold over the elements of a structure,
-- associating to the right, but strictly.
-- | Fold over the elements of a structure,
-- associating to the right, but strictly.