[commit: ghc] master: Add explicit foldMap implementation for Maybe (bf1e1f3)

git at git.haskell.org git at git.haskell.org
Thu Jan 19 21:43:16 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/bf1e1f3206f8b274c3ffa33cd7688a0b17eabd0b/ghc

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

commit bf1e1f3206f8b274c3ffa33cd7688a0b17eabd0b
Author: David Feuer <david.feuer at gmail.com>
Date:   Thu Jan 19 16:40:06 2017 -0500

    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


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

bf1e1f3206f8b274c3ffa33cd7688a0b17eabd0b
 libraries/base/Data/Foldable.hs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index ce097df..0a8b003 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
 



More information about the ghc-commits mailing list