oops (was: Re: if-then-else inside a "do")

Bernard James POPE bjpop@cs.mu.OZ.AU
Wed, 30 Jan 2002 15:11:27 +1100 (EST)


Oops,

Thanks to Kevin who pointed out:

when             :: (Monad m) => Bool -> m () -> m ()
when p s          = if p then s else return ()

unless           :: (Monad m) => Bool -> m () -> m ()
unless p s        = when (not p) s


> So now I tend to use:
> 
>    doIf :: Monad a => Bool -> [a b] -> a ()
>    doIf b e = if b then sequence_ e else return ()

Bernie.