[commit: ghc] master: Add a strict version of foldMap to Foldable (172b00c)
git at git.haskell.org
git at git.haskell.org
Tue Oct 16 00:51:21 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/172b00c1954d8eb609ccd58a731ae89fe74a7489/ghc
>---------------------------------------------------------------
commit 172b00c1954d8eb609ccd58a731ae89fe74a7489
Author: Simon Jakobi <simon.jakobi at gmail.com>
Date: Mon Oct 15 13:55:37 2018 -0400
Add a strict version of foldMap to Foldable
Summary:
Original proposal by Andrew Martin:
https://mail.haskell.org/pipermail/libraries/2018-June/028852.html
Reviewers: andrewthad, hvr, bgamari, alpmestan, tdammers
Reviewed By: bgamari, alpmestan, tdammers
Subscribers: alpmestan, rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4924
>---------------------------------------------------------------
172b00c1954d8eb609ccd58a731ae89fe74a7489
libraries/base/Data/Foldable.hs | 6 ++++++
libraries/base/changelog.md | 2 ++
2 files changed, 8 insertions(+)
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index f5f3112..cc0f348 100644
--- a/libraries/base/Data/Foldable.hs
+++ b/libraries/base/Data/Foldable.hs
@@ -130,6 +130,12 @@ class Foldable t where
-- This INLINE allows more list functions to fuse. See Trac #9848.
foldMap f = foldr (mappend . f) mempty
+ -- | A variant of 'foldMap' that is strict in the accumulator.
+ --
+ -- @since 4.13.0.0
+ foldMap' :: Monoid m => (a -> m) -> t a -> m
+ foldMap' f = foldl' (\ acc a -> acc <> f a) mempty
+
-- | Right-associative fold of a structure.
--
-- In the case of lists, 'foldr', when applied to a binary operator, a
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 3709a0a..bfa8cb9 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -10,6 +10,8 @@
a representational one. There is really no reason to care about the
type of the underlying object.
+ * Add `foldMap'`, a strict version of `foldMap`, to `Foldable`.
+
## 4.12.0.0 *TBA*
* Bundled with GHC *TBA*
More information about the ghc-commits
mailing list