[Haskell] ANN: monadLib 2.0
Iavor Diatchki
iavor.diatchki at gmail.com
Thu Mar 23 14:51:58 EST 2006
Hello,
On 3/23/06, Udo Stenzel <u.stenzel at web.de> wrote:
> Iavor Diatchki wrote:
>...
> But usually p comes from a monadic computation, so in reality you need
>
> *> do { p' <- p ; if p' then do { a <- m ; e1 } else e2 }
>
> which I find excessively ugly. Actually this is not a case for when,
> it's one for cond:
>
> *> cond t f True = t
> *> cond t f False = f
>
> *> p >>= cond (do { a <- m ; e1 }) e2
In the Monad.Combinatros module of 'monadLib' there is the 'ifM'
combinator which is kind of like the above:
ifM :: Monad m => m Bool -> m a -> m a -> m a
You could write:
ifM p (do { a <- m; e1 }) e2
The combinator 'whenM' is just a special case:
whenM p m = ifM p m (return ())
.
-Iavor
More information about the Libraries
mailing list