, sequence -- :: (Monad m) => [m a] -> m [a]
, sequence_ -- :: (Monad m) => [m a] -> m ()
, (=<<) -- :: (Monad m) => (a -> m b) -> m a -> m b
+ , (>=>) -- :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c)
+ , (<=<) -- :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c)
+ , forever -- :: (Monad m) => m a -> m ()
-- ** Generalisations of list functions
ys <- filterM p xs
return (if flg then x:ys else ys)
--- | @'forM' f@ is @'mapM'@ with its arguments flipped
+-- | 'forM' is 'mapM' with its arguments flipped
forM :: Monad m => [a] -> (a -> m b) -> m [b]
{-# INLINE forM #-}
forM = flip mapM
--- | @'forM_' f@ is @'mapM_'@ with its arguments flipped
+-- | 'forM_' is 'mapM_' with its arguments flipped
forM_ :: Monad m => [a] -> (a -> m b) -> m ()
{-# INLINE forM_ #-}
forM_ = flip mapM_
{-# INLINE msum #-}
msum = foldr mplus mzero
+infixr 1 <=<, >=>
+
+-- | Left-to-right Kleisli composition of monads.
+(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c)
+f >=> g = \x -> f x >>= g
+
+-- | Right-to-left Kleisli composition of monads. '(>=>)', with the arguments flipped
+(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> (a -> m c)
+(<=<) = flip (>=>)
+
+-- | @'forever' act@ repeats the action infinitely.
+forever :: (Monad m) => m a -> m ()
+forever a = a >> forever a
+
-- -----------------------------------------------------------------------------
-- Other monad functions
ap :: (Monad m) => m (a -> b) -> m a -> m b
ap = liftM2 id
+
{- $naming
The functions in this library use the following naming conventions: