[commit: ghc] master: Generalise constraint on `instance Monoid (Maybe a)` to Semigroup (10ca801)

git at git.haskell.org git at git.haskell.org
Tue Sep 19 05:58:08 UTC 2017


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

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

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

commit 10ca8018900364579123bf3912202176d338d3c6
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Tue Sep 19 07:54:40 2017 +0200

    Generalise constraint on `instance Monoid (Maybe a)` to Semigroup
    
    This now becomes possible due to the introduction of the
    Semigroup=>Monoid superclass relation (see #14191).
    
    Reviewers: ekmett, RyanGlScott, austin, bgamari
    
    Reviewed By: ekmett, RyanGlScott, bgamari
    
    Subscribers: rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3972


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

10ca8018900364579123bf3912202176d338d3c6
 libraries/base/GHC/Base.hs                | 9 +++++----
 libraries/base/changelog.md               | 3 +++
 testsuite/tests/ghci/scripts/T4175.stdout | 2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
index 82b99a8..052f13f 100644
--- a/libraries/base/GHC/Base.hs
+++ b/libraries/base/GHC/Base.hs
@@ -413,12 +413,13 @@ instance Semigroup a => Semigroup (Maybe a) where
 -- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to
 -- <http://en.wikipedia.org/wiki/Monoid>: \"Any semigroup @S@ may be
 -- turned into a monoid simply by adjoining an element @e@ not in @S@
--- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S at .\" Since
--- there used to be no \"Semigroup\" typeclass providing just 'mappend',
--- we use 'Monoid' instead.
+-- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S at .\"
+--
+-- /Since 4.11.0/: constraint on inner @a@ value generalised from
+-- 'Monoid' to 'Semigroup'.
 --
 -- @since 2.01
-instance Monoid a => Monoid (Maybe a) where
+instance Semigroup a => Monoid (Maybe a) where
     mempty = Nothing
 
 -- | For tuples, the 'Monoid' constraint on @a@ determines
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index eac53ba..f641299 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -14,6 +14,9 @@
     export `Semigroup` from `Prelude`; remove `Monoid` reexport
     from `Data.Semigroup` (#14191).
 
+  * Generalise `instance Monoid a => Monoid (Maybe a)` to
+    `instance Semigroup a => Monoid (Maybe a)`.
+
   * Add `infixl 9 !!` declaration for `Data.List.NonEmpty.!!`
 
   * Add `<&>` operator to `Data.Functor` (#14029)
diff --git a/testsuite/tests/ghci/scripts/T4175.stdout b/testsuite/tests/ghci/scripts/T4175.stdout
index 7b630f1..c7421b5 100644
--- a/testsuite/tests/ghci/scripts/T4175.stdout
+++ b/testsuite/tests/ghci/scripts/T4175.stdout
@@ -34,7 +34,7 @@ instance Applicative Maybe -- Defined in ‘GHC.Base’
 instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Base’
 instance Functor Maybe -- Defined in ‘GHC.Base’
 instance Monad Maybe -- Defined in ‘GHC.Base’
-instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
+instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
 instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Base’
 instance Semigroup a => Semigroup (Maybe a)
   -- Defined in ‘GHC.Base’



More information about the ghc-commits mailing list