[commit: ghc] master: Add `Monoid` instance for `IO` (65d4b89)

git at git.haskell.org git at git.haskell.org
Tue Jun 16 21:40:28 UTC 2015


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/65d4b895d8331ff9e7df6aaf0a0de898c857201c/ghc

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

commit 65d4b895d8331ff9e7df6aaf0a0de898c857201c
Author: Gabriel Gonzalez <Gabriel439 at gmail.com>
Date:   Tue Jun 16 16:38:18 2015 -0500

    Add `Monoid` instance for `IO`
    
    See original proposal at
    https://mail.haskell.org/pipermail/libraries/2014-November/024310.html
    for more details
    
    Reviewed By: hvr, austin
    
    Differential Revision: https://phabricator.haskell.org/D988
    
    GHC Trac Issues: #10523


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

65d4b895d8331ff9e7df6aaf0a0de898c857201c
 libraries/base/GHC/Base.hs  | 4 ++++
 libraries/base/changelog.md | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
index 79942d8..e15519d 100644
--- a/libraries/base/GHC/Base.hs
+++ b/libraries/base/GHC/Base.hs
@@ -312,6 +312,10 @@ instance Monoid a => Monad ((,) a) where
     return x = (mempty, x)
     (u, a) >>= k = case k a of (v, b) -> (u `mappend` v, b)
 
+instance Monoid a => Monoid (IO a) where
+    mempty = pure mempty
+    mappend = liftA2 mappend
+
 {- | The 'Functor' class is used for types that can be mapped over.
 Instances of 'Functor' should satisfy the following laws:
 
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index ad3a74d..df691e3 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -35,6 +35,8 @@
 
   * `Data.Version.Version` now has a `Generic` instance
 
+  * `IO` now has a `Monoid` instance
+
 ## 4.8.1.0  *TBA*
 
   * Bundled with GHC 7.10.2



More information about the ghc-commits mailing list