Remove redundant "Minimal complete definition"-comments
[ghc.git] / libraries / base / Control / Monad / Zip.hs
1 {-# LANGUAGE Safe #-}
2
3 -----------------------------------------------------------------------------
4 -- |
5 -- Module : Control.Monad.Zip
6 -- Copyright : (c) Nils Schweinsberg 2011,
7 -- (c) George Giorgidze 2011
8 -- (c) University Tuebingen 2011
9 -- License : BSD-style (see the file libraries/base/LICENSE)
10 -- Maintainer : libraries@haskell.org
11 -- Stability : experimental
12 -- Portability : portable
13 --
14 -- Monadic zipping (used for monad comprehensions)
15 --
16 -----------------------------------------------------------------------------
17
18 module Control.Monad.Zip where
19
20 import Control.Monad (liftM)
21
22 -- | `MonadZip` type class. Minimal definition: `mzip` or `mzipWith`
23 --
24 -- Instances should satisfy the laws:
25 --
26 -- * Naturality :
27 --
28 -- > liftM (f *** g) (mzip ma mb) = mzip (liftM f ma) (liftM g mb)
29 --
30 -- * Information Preservation:
31 --
32 -- > liftM (const ()) ma = liftM (const ()) mb
33 -- > ==>
34 -- > munzip (mzip ma mb) = (ma, mb)
35 --
36 class Monad m => MonadZip m where
37 {-# MINIMAL mzip | mzipWith #-}
38
39 mzip :: m a -> m b -> m (a,b)
40 mzip = mzipWith (,)
41
42 mzipWith :: (a -> b -> c) -> m a -> m b -> m c
43 mzipWith f ma mb = liftM (uncurry f) (mzip ma mb)
44
45 munzip :: m (a,b) -> (m a, m b)
46 munzip mab = (liftM fst mab, liftM snd mab)
47 -- munzip is a member of the class because sometimes
48 -- you can implement it more efficiently than the
49 -- above default code. See Trac #4370 comment by giorgidze
50
51 instance MonadZip [] where
52 mzip = zip
53 mzipWith = zipWith
54 munzip = unzip
55