[commit: ghc] master: Add more MonadZip instances (3f3782d)
git at git.haskell.org
git at git.haskell.org
Tue Mar 17 16:07:21 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/3f3782df63f7c55382a25687a8e5c7f64202fa0a/ghc
>---------------------------------------------------------------
commit 3f3782df63f7c55382a25687a8e5c7f64202fa0a
Author: Oleg Grenrus <oleg.grenrus at iki.fi>
Date: Tue Mar 17 11:03:44 2015 -0500
Add more MonadZip instances
Summary: Add MonadZip Alt and MonadFix Alt instances
Reviewers: ekmett, dfeuer, hvr, austin
Reviewed By: austin
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D716
GHC Trac Issues: #10107
>---------------------------------------------------------------
3f3782df63f7c55382a25687a8e5c7f64202fa0a
libraries/base/Control/Monad/Fix.hs | 6 +++++-
libraries/base/Control/Monad/Zip.hs | 24 +++++++++++++++++++++++-
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/libraries/base/Control/Monad/Fix.hs b/libraries/base/Control/Monad/Fix.hs
index ef8eeee..ae37911 100644
--- a/libraries/base/Control/Monad/Fix.hs
+++ b/libraries/base/Control/Monad/Fix.hs
@@ -26,7 +26,8 @@ module Control.Monad.Fix (
import Data.Either
import Data.Function ( fix )
import Data.Maybe
-import Data.Monoid ( Dual(..), Sum(..), Product(..), First(..), Last(..) )
+import Data.Monoid ( Dual(..), Sum(..), Product(..)
+ , First(..), Last(..), Alt(..) )
import GHC.Base ( Monad, error, (.) )
import GHC.List ( head, tail )
import GHC.ST
@@ -99,3 +100,6 @@ instance MonadFix First where
instance MonadFix Last where
mfix f = Last (mfix (getLast . f))
+
+instance MonadFix f => MonadFix (Alt f) where
+ mfix f = Alt (mfix (getAlt . f))
diff --git a/libraries/base/Control/Monad/Zip.hs b/libraries/base/Control/Monad/Zip.hs
index df096b1..1f63cab 100644
--- a/libraries/base/Control/Monad/Zip.hs
+++ b/libraries/base/Control/Monad/Zip.hs
@@ -17,7 +17,8 @@
module Control.Monad.Zip where
-import Control.Monad (liftM)
+import Control.Monad (liftM, liftM2)
+import Data.Monoid
-- | `MonadZip` type class. Minimal definition: `mzip` or `mzipWith`
--
@@ -53,3 +54,24 @@ instance MonadZip [] where
mzipWith = zipWith
munzip = unzip
+instance MonadZip Dual where
+ -- Cannot use coerce, it's unsafe
+ mzipWith = liftM2
+
+instance MonadZip Sum where
+ mzipWith = liftM2
+
+instance MonadZip Product where
+ mzipWith = liftM2
+
+instance MonadZip Maybe where
+ mzipWith = liftM2
+
+instance MonadZip First where
+ mzipWith = liftM2
+
+instance MonadZip Last where
+ mzipWith = liftM2
+
+instance MonadZip f => MonadZip (Alt f) where
+ mzipWith f (Alt ma) (Alt mb) = Alt (mzipWith f ma mb)
More information about the ghc-commits
mailing list