diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2017-09-19 07:54:40 +0200 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2017-09-19 07:56:52 +0200 |
commit | 10ca8018900364579123bf3912202176d338d3c6 (patch) | |
tree | e04509b6684a150c91e35e64c9d8ebbd658ad21b | |
parent | 120c568a0b400fecde1cd60f665df104785e6d49 (diff) | |
download | haskell-10ca8018900364579123bf3912202176d338d3c6.tar.gz |
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
-rw-r--r-- | libraries/base/GHC/Base.hs | 9 | ||||
-rw-r--r-- | libraries/base/changelog.md | 3 | ||||
-rw-r--r-- | 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 82b99a88c2..052f13fbe6 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@.\" 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@.\" +-- +-- /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 eac53ba079..f64129965f 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 7b630f1ed9..c7421b58af 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’ |