Commit 3f3782df authored by Oleg Grenrus's avatar Oleg Grenrus Committed by Austin Seipp

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
parent dbd92997
......@@ -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))
......@@ -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)
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