diff options
author | David Feuer <david.feuer@gmail.com> | 2017-01-19 16:40:06 -0500 |
---|---|---|
committer | David Feuer <David.Feuer@gmail.com> | 2017-01-19 16:40:07 -0500 |
commit | bf1e1f3206f8b274c3ffa33cd7688a0b17eabd0b (patch) | |
tree | 03cc00a67018231e734073fc0caff206fa6e22c9 /libraries | |
parent | f07a6c17a3d6b32cc64b0b8318a05177fc098630 (diff) | |
download | haskell-bf1e1f3206f8b274c3ffa33cd7688a0b17eabd0b.tar.gz |
Add explicit foldMap implementation for Maybe
Eric Mertens pointed out that using the default `foldMap`
implementation for `Maybe` led to an efficiency problem by
implementing `foldMap f (Just x)` as `f x <> mempty` rather than
as `f x`. This should solve the problem.
Reviewers: hvr, austin, bgamari
Reviewed By: bgamari
Subscribers: glguy, thomie
Differential Revision: https://phabricator.haskell.org/D2988
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Foldable.hs | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs index ce097df581..0a8b00380d 100644 --- a/libraries/base/Data/Foldable.hs +++ b/libraries/base/Data/Foldable.hs @@ -270,6 +270,8 @@ class Foldable t where -- | @since 2.01 instance Foldable Maybe where + foldMap = maybe mempty + foldr _ z Nothing = z foldr f z (Just x) = f x z |