{-# LANGUAGE Safe #-}
------------------------------------------------------------------------------- |-- Module : Control.Monad.Zip-- Copyright : (c) Nils Schweinsberg 2011,-- (c) George Giorgidze 2011-- (c) University Tuebingen 2011-- License : BSD-style (see the file libraries/base/LICENSE)-- Maintainer : libraries@haskell.org-- Stability : experimental-- Portability : portable---- Monadic zipping (used for monad comprehensions)-------------------------------------------------------------------------------
module Control.Monad.Zip where
import Prelude
import Control.Monad (liftM)
-- | `MonadZip` type class. Minimal definition: `mzip` or `mzipWith`---- Instances should satisfy the laws:---- * Naturality :---- > liftM (f *** g) (mzip ma mb) = mzip (liftM f ma) (liftM g mb)---- * Information Preservation:---- > liftM (const ()) ma = liftM (const ()) mb-- > ==>-- > munzip (mzip ma mb) = (ma, mb)--
class Monad m =>MonadZipm where
mzip :: ma -> mb -> m (a,b)
mzip = mzipWith(,)mzipWith :: (a -> b -> c) -> ma -> mb -> mcmzipWithfmamb = liftM (uncurryf) (mzipmamb)
munzip :: m (a,b) -> (ma, mb)
munzipmab = (liftMfstmab, liftMsndmab)
-- munzip is a member of the class because sometimes-- you can implement it more efficiently than the-- above default code. See Trac #4370 comment by giorgidze{-# MINIMAL mzip | mzipWith #-}
instance MonadZip[] where
mzip = zipmzipWith = zipWithmunzip = unzip