| Portability | portable |
|---|---|
| Stability | experimental |
| Maintainer | wren@community.haskell.org |
Control.Monad.Extras
Description
Some basic monad combinators that Control.Monad lacks. Many
of these functions have been adopted by the IfElse package:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/IfElse
- ifM :: Monad m => m Bool -> m a -> m a -> m a
- whenM :: Monad m => m Bool -> m () -> m ()
- unlessM :: Monad m => m Bool -> m () -> m ()
- whileM :: Monad m => m Bool -> m () -> m ()
- untilM :: Monad m => m Bool -> m () -> m ()
- return' :: Monad m => a -> m a
- returning :: Monad m => (a -> m b) -> a -> m a
- liftM' :: Monad m => (a -> b) -> m a -> m b
- maybeMP :: MonadPlus m => Maybe a -> m a
- maybeEither :: a -> Maybe b -> Either a b
Monadic conditionals
ifM :: Monad m => m Bool -> m a -> m a -> m aSource
Choose a computation to run based on the boolean.
unlessM :: Monad m => m Bool -> m () -> m ()Source
If the boolean is false, then run the computation.
Looping constructs
whileM :: Monad m => m Bool -> m () -> m ()Source
Execute a monadic action so long as a monadic boolean returns true.
untilM :: Monad m => m Bool -> m () -> m ()Source
Negation of whileM: execute an action so long as the boolean
returns false.
Specialized returns
return' :: Monad m => a -> m aSource
Strict version of return because usually we don't need that
extra thunk.
returning :: Monad m => (a -> m b) -> a -> m aSource
Take an action and make it into a side-effecting return.
Because I seem to keep running into m () and the like.
This is the moral inverse of Control.Monad.void :: Functor f
=> f a -> f () which is added in base-4.3.0.0.