Commit 8c6a3d68 authored by Ryan Scott's avatar Ryan Scott
Browse files

Add missing Semigroup instances for Monoidal datatypes in base

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:

GHC Trac Issues: #12464
parent 90df91a0
......@@ -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
instance Semigroup a => Semigroup (IO a) where
(<>) = liftA2 (<>)
-- | @since
instance Semigroup Event where
(<>) = mappend
stimes = stimesMonoid
-- | @since
instance Semigroup Lifetime where
(<>) = mappend
stimes = stimesMonoid
......@@ -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)
## *May 2016*
* Bundled with GHC 8.0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment