diff options
author | Oleg Grenrus <oleg.grenrus@iki.fi> | 2015-03-17 11:03:44 -0500 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2015-03-17 11:03:45 -0500 |
commit | 3f3782df63f7c55382a25687a8e5c7f64202fa0a (patch) | |
tree | 6be82db01ae602ed9771480dd7ea0636d2136d34 | |
parent | dbd929971c05b5a05129029657a354ddfb658e61 (diff) | |
download | haskell-3f3782df63f7c55382a25687a8e5c7f64202fa0a.tar.gz |
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
-rw-r--r-- | libraries/base/Control/Monad/Fix.hs | 6 | ||||
-rw-r--r-- | 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 ef8eeee776..ae37911c18 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 df096b1e81..1f63cab3d7 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) |