Module Control.Monad


Exported Functions: <=<, >=>, filterM, foldM, foldM_, forever, forM, forM_, join, liftM3, mapAndUnzipM, replicateM, replicateM_, unless, void, zipWithM, zipWithM_


Exported Functions


filterM :: Applicative b => (a -> b Bool) -> [a] -> b [a]  Deterministic 

This generalizes the list-based filter function.


(>=>) :: Monad b => (a -> b c) -> (c -> b d) -> a -> b d  Deterministic 

Left-to-right composition of Kleisli arrows.

Further infos:
  • defined as right-associative infix operator with precedence 1

(<=<) :: Monad b => (a -> b c) -> (d -> b a) -> d -> b c  Deterministic 

Right-to-left composition of Kleisli arrows. @(>=>)@, with the arguments flipped.

Further infos:
  • defined as right-associative infix operator with precedence 1

forever :: Applicative a => a b -> a c  Deterministic 

Repeat an action indefinitely.


mapAndUnzipM :: Applicative b => (a -> b (c, d)) -> [a] -> b ([c], [d])  Deterministic 

The mapAndUnzipM function maps its first argument over a list, returning the result as a pair of lists. This function is mainly used with complicated data structures or a state-transforming monad.


zipWithM :: Applicative c => (a -> b -> c d) -> [a] -> [b] -> c [d]  Deterministic 

The zipWithM function generalizes zipWith to arbitrary applicative functors.


zipWithM_ :: Applicative c => (a -> b -> c d) -> [a] -> [b] -> c ()  Deterministic 

zipWithM_ is the extension of zipWithM which ignores the final result.


foldM :: Monad c => (a -> b -> c a) -> a -> [b] -> c a  Deterministic 

The foldM function is analogous to foldl, except that its result is encapsulated in a monad.


foldM_ :: Monad c => (a -> b -> c a) -> a -> [b] -> c ()  Deterministic 

Like foldM, but discards the result.


replicateM :: Applicative a => Int -> a b -> a [b]  Deterministic 

@replicateM n act@ performs the action @n@ times, gathering the results.


replicateM_ :: Applicative a => Int -> a b -> a ()  Deterministic 

Like replicateM, but discards the result.


unless :: Applicative a => Bool -> a () -> a ()  Deterministic 

The reverse of when.


liftM3 :: Monad e => (a -> b -> c -> d) -> e a -> e b -> e c -> e d  Deterministic 

Promotes a ternary function to a monad. The function arguments are scanned from left to right.

Examples:

> liftM3 (\x y z -> x+y+z) [1,2] [3,4] [5,6]
[9,10,10,11,10,11,11,12]
> liftM3 (,,) [1,2] [3,4] [5,6]

[(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)]


join :: Monad a => a (a b) -> a b  Deterministic 

Removes one level of monadic structure, i.e. flattens the monad.


void :: Functor a => a b -> a ()  Deterministic 

Ignores the result of the evaluation.


forM :: Monad b => [a] -> (a -> b c) -> b [c]  Deterministic 

forM is mapM with its arguments flipped.


forM_ :: Monad b => [a] -> (a -> b c) -> b ()  Deterministic 

forM_ is mapM_ with its arguments flipped. It is useful for writing imperative-style loops:

main = forM_ [1, 2, 3] $ \i -> print i