[commit: ghc] master: Add missing Semigroup instances for Monoidal datatypes in base (8c6a3d6)

git at git.haskell.org git at git.haskell.org
Fri Oct 14 14:33:15 UTC 2016


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

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

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

commit 8c6a3d68c0301bb985aa2a462936bbcf7584ae9c
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Fri Oct 14 10:30:54 2016 -0400

    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


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

8c6a3d68c0301bb985aa2a462936bbcf7584ae9c
 libraries/base/Data/Semigroup.hs | 15 +++++++++++++++
 libraries/base/changelog.md      |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/libraries/base/Data/Semigroup.hs b/libraries/base/Data/Semigroup.hs
index 88942ad..2cb1bb7 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 d2cc421..a01c878 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



More information about the ghc-commits mailing list