diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2016-10-14 10:30:54 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2016-10-14 10:30:54 -0400 |
commit | 8c6a3d68c0301bb985aa2a462936bbcf7584ae9c (patch) | |
tree | 1b4865284dcdcf94f25af5c76fbb40f15588bc95 /libraries | |
parent | 90df91a067ec6a2fccc4b740cb3006e6ff3258cf (diff) | |
download | haskell-8c6a3d68c0301bb985aa2a462936bbcf7584ae9c.tar.gz |
Add missing Semigroup instances for Monoidal datatypes in base
Summary:
There are currently three datatypes that are exposed in `base` that have
`Monoid` instances, but no `Semigroup` instances:
* `IO`
* `Event` (from `GHC.Event`)
* `Lifetime` (from `GHC.Event`)
(There is also `EventLifetime` in `GHC.Event.Internal`, but it is not exported
directly, so I didn't bother with it.)
Adding the `Semigroup` instances for these types directly in the modules in
which they're defined resulted in some horrific import cycles, so I opted to
take the easy approach of defining all of these instances in `Data.Semigroup`.
(When `Semigroup` becomes a superclass of `Monoid`, these instances will have
to be moved somehow.)
Fixes #12464.
Test Plan: It compiles
Reviewers: hvr, ekmett, austin, bgamari
Reviewed By: ekmett
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2588
GHC Trac Issues: #12464
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Semigroup.hs | 15 | ||||
-rw-r--r-- | libraries/base/changelog.md | 3 |
2 files changed, 18 insertions, 0 deletions
diff --git a/libraries/base/Data/Semigroup.hs b/libraries/base/Data/Semigroup.hs index 88942ad7d0..2cb1bb75cf 100644 --- a/libraries/base/Data/Semigroup.hs +++ b/libraries/base/Data/Semigroup.hs @@ -83,6 +83,7 @@ import Data.Monoid (All (..), Any (..), Dual (..), Endo (..), import Data.Monoid (Alt (..)) import qualified Data.Monoid as Monoid import Data.Void +import GHC.Event (Event, Lifetime (..)) import GHC.Generics infixr 6 <> @@ -705,3 +706,17 @@ instance Semigroup (Proxy s) where _ <> _ = Proxy sconcat _ = Proxy stimes _ _ = Proxy + +-- | @since 4.10.0.0 +instance Semigroup a => Semigroup (IO a) where + (<>) = liftA2 (<>) + +-- | @since 4.10.0.0 +instance Semigroup Event where + (<>) = mappend + stimes = stimesMonoid + +-- | @since 4.10.0.0 +instance Semigroup Lifetime where + (<>) = mappend + stimes = stimesMonoid diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index d2cc42159b..a01c878a53 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -23,6 +23,9 @@ `ReadS`, as well as related combinators, have been added to `Data.Functor.Classes` (#12358) + * Add `Semigroup` instance for `IO`, as well as for `Event` and `Lifetime` + from `GHC.Event` (#12464) + ## 4.9.0.0 *May 2016* * Bundled with GHC 8.0 |