X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Control%2FMonad.hs;h=3080f5f38f1bbe3570b71388829e161494755329;hb=14da16d09dcd148b9a833254a5cfe8e9f2ff829d;hp=32f04036f2b685466f663800af74e4c7c5978836;hpb=e4c92ded9108b12c7996b5769fa2ee5914f42f1d;p=haskell-directory.git diff --git a/Control/Monad.hs b/Control/Monad.hs index 32f0403..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 @@ -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: