{-# LANGUAGE Safe #-}{-# LANGUAGE TypeOperators #-}------------------------------------------------------------------------------- |-- 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)-------------------------------------------------------------------------------moduleControl.Monad.ZipwhereimportControl.Monad (liftM ,liftM2 )importData.Monoid importData.Proxy importGHC.Generics -- | `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)--classMonad m =>MonadZip m where{-# MINIMAL mzip | mzipWith #-}mzip::m a ->m b ->m (a ,b )mzip =mzipWith (,)mzipWith::(a ->b ->c )->m a ->m b ->m c mzipWith f ma mb =liftM (uncurry f )(mzip ma mb )munzip::m (a ,b )->(m a ,m b )munzip mab =(liftM fst mab ,liftM snd mab )-- 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 giorgidzeinstanceMonadZip []wheremzip =zip mzipWith =zipWith munzip =unzip instanceMonadZip Dual where-- Cannot use coerce, it's unsafemzipWith =liftM2 instanceMonadZip Sum wheremzipWith =liftM2 instanceMonadZip Product wheremzipWith =liftM2 instanceMonadZip Maybe wheremzipWith =liftM2 instanceMonadZip First wheremzipWith =liftM2 instanceMonadZip Last wheremzipWith =liftM2 instanceMonadZip f =>MonadZip (Alt f )wheremzipWith f (Alt ma )(Alt mb )=Alt (mzipWith f ma mb )instanceMonadZip Proxy wheremzipWith ___=Proxy -- Instances for GHC.GenericsinstanceMonadZip U1 wheremzipWith ___=U1 instanceMonadZip Par1 wheremzipWith =liftM2 instanceMonadZip f =>MonadZip (Rec1 f )wheremzipWith f (Rec1 fa )(Rec1 fb )=Rec1 (mzipWith f fa fb )instanceMonadZip f =>MonadZip (M1 i c f )wheremzipWith f (M1 fa )(M1 fb )=M1 (mzipWith f fa fb )instance(MonadZip f ,MonadZip g )=>MonadZip (f :*:g )wheremzipWith f (x1 :*: y1 )(x2 :*: y2 )=mzipWith f x1 x2 :*: mzipWith f y1 y2 

AltStyle によって変換されたページ (->オリジナル) /