X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Control%2FMonad.hs;h=3080f5f38f1bbe3570b71388829e161494755329;hb=6b1a36a595eddf1e124529646afdb75c76a9966d;hp=bb1ca98c0f7f3e325b2b595c7ceb4c7214d0a3cd;hpb=b5dd194466259e21a422af356f8d2e83bfd85a09;p=haskell-directory.git diff --git a/Control/Monad.hs b/Control/Monad.hs index bb1ca98..3080f5f 100644 --- a/Control/Monad.hs +++ b/Control/Monad.hs @@ -37,6 +37,9 @@ module Control.Monad , 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 @@ -157,12 +160,12 @@ filterM p (x:xs) = do 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_ @@ -173,6 +176,20 @@ msum :: MonadPlus m => [m a] -> m a {-# 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 @@ -290,6 +307,7 @@ is equivalent to ap :: (Monad m) => m (a -> b) -> m a -> m b ap = liftM2 id + {- $naming The functions in this library use the following naming conventions: