Exported Functions: <=<, >=>, filterM, foldM, foldM_, forever, forM, forM_, join, liftM3, mapAndUnzipM, replicateM, replicateM_, unless, void, zipWithM, zipWithM_
filterM
:: Applicative b => (a -> b Bool) -> [a] -> b [a]
This generalizes the list-based filter function.
(>=>)
:: Monad b => (a -> b c) -> (c -> b d) -> a -> b d
Left-to-right composition of Kleisli arrows.
(<=<)
:: Monad b => (a -> b c) -> (d -> b a) -> d -> b c
Right-to-left composition of Kleisli arrows. @(>=>)@, with the arguments flipped.
forever
:: Applicative a => a b -> a c
Repeat an action indefinitely.
mapAndUnzipM
:: Applicative b => (a -> b (c, d)) -> [a] -> b ([c], [d])
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]
The zipWithM function generalizes zipWith to arbitrary applicative functors.
zipWithM_
:: Applicative c => (a -> b -> c d) -> [a] -> [b] -> c ()
zipWithM_ is the extension of zipWithM which ignores the final result.
foldM
:: Monad c => (a -> b -> c a) -> a -> [b] -> c a
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 ()
Like foldM, but discards the result.
replicateM
:: Applicative a => Int -> a b -> a [b]
@replicateM n act@ performs the action @n@ times, gathering the results.
replicateM_
:: Applicative a => Int -> a b -> a ()
Like replicateM, but discards the result.
unless
:: Applicative a => Bool -> a () -> a ()
The reverse of when.
liftM3
:: Monad e => (a -> b -> c -> d) -> e a -> e b -> e c -> e d
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
Removes one level of monadic structure, i.e. flattens the monad.
void
:: Functor a => a b -> a ()
Ignores the result of the evaluation.
forM
:: Monad b => [a] -> (a -> b c) -> b [c]
forM
is mapM
with its arguments flipped.
forM_
:: Monad b => [a] -> (a -> b c) -> b ()
forM_
is mapM_
with its arguments flipped.
It is useful for writing imperative-style loops:
main = forM_ [1, 2, 3] $ \i -> print i