Remove obsolete `-fno-warn-unused-imports`
[packages/haskell2010.git] / Control / Monad.hs
1 #if __GLASGOW_HASKELL__ >= 701
2 {-# LANGUAGE Safe #-}
3 #endif
4
5 -- |
6 -- The "Control.Monad" module provides the 'Functor', 'Monad' and
7 -- 'MonadPlus' classes, together with some useful operations on monads.
8
9 module Control.Monad (
10 -- * Functor and monad classes
11
12 Functor(fmap)
13 , Monad((>>=), (>>), return, fail)
14
15 , MonadPlus ( -- class context: Monad
16 mzero -- :: (MonadPlus m) => m a
17 , mplus -- :: (MonadPlus m) => m a -> m a -> m a
18 )
19 -- * Functions
20
21 -- ** Naming conventions
22 -- $naming
23
24 -- ** Basic @Monad@ functions
25
26 , mapM -- :: (Monad m) => (a -> m b) -> [a] -> m [b]
27 , mapM_ -- :: (Monad m) => (a -> m b) -> [a] -> m ()
28 , forM -- :: (Monad m) => [a] -> (a -> m b) -> m [b]
29 , forM_ -- :: (Monad m) => [a] -> (a -> m b) -> m ()
30 , sequence -- :: (Monad m) => [m a] -> m [a]
31 , sequence_ -- :: (Monad m) => [m a] -> m ()
32 , (=<<) -- :: (Monad m) => (a -> m b) -> m a -> m b
33 , (>=>) -- :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c)
34 , (<=<) -- :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c)
35 , forever -- :: (Monad m) => m a -> m b
36 , void
37
38 -- ** Generalisations of list functions
39
40 , join -- :: (Monad m) => m (m a) -> m a
41 , msum -- :: (MonadPlus m) => [m a] -> m a
42 , filterM -- :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
43 , mapAndUnzipM -- :: (Monad m) => (a -> m (b,c)) -> [a] -> m ([b], [c])
44 , zipWithM -- :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m [c]
45 , zipWithM_ -- :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m ()
46 , foldM -- :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
47 , foldM_ -- :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()
48 , replicateM -- :: (Monad m) => Int -> m a -> m [a]
49 , replicateM_ -- :: (Monad m) => Int -> m a -> m ()
50
51 -- ** Conditional execution of monadic expressions
52
53 , guard -- :: (MonadPlus m) => Bool -> m ()
54 , when -- :: (Monad m) => Bool -> m () -> m ()
55 , unless -- :: (Monad m) => Bool -> m () -> m ()
56
57 -- ** Monadic lifting operators
58
59 , liftM -- :: (Monad m) => (a -> b) -> (m a -> m b)
60 , liftM2 -- :: (Monad m) => (a -> b -> c) -> (m a -> m b -> m c)
61 , liftM3 -- :: ...
62 , liftM4 -- :: ...
63 , liftM5 -- :: ...
64
65 , ap -- :: (Monad m) => m (a -> b) -> m a -> m b
66
67 ) where
68 import "base" Control.Monad
69
70 {- $naming
71
72 The functions in this library use the following naming conventions:
73
74 * A postfix \'@M@\' always stands for a function in the Kleisli category:
75 The monad type constructor @m@ is added to function results
76 (modulo currying) and nowhere else. So, for example,
77
78 > filter :: (a -> Bool) -> [a] -> [a]
79 > filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
80
81 * A postfix \'@_@\' changes the result type from @(m a)@ to @(m ())@.
82 Thus, for example:
83
84 > sequence :: Monad m => [m a] -> m [a]
85 > sequence_ :: Monad m => [m a] -> m ()
86
87 * A prefix \'@m@\' generalizes an existing function to a monadic form.
88 Thus, for example:
89
90 > sum :: Num a => [a] -> a
91 > msum :: MonadPlus m => [m a] -> m a
92
93 -}