if-then-else inside a "do"
Bernard James POPE
bjpop@cs.mu.OZ.AU
Wed, 30 Jan 2002 14:19:47 +1100 (EST)
Hi again,
Forgot to mention this in my last email. I find myself writing a lot
of if-then-elses in do notation, and most often the else branch is "return ()".
This gets a bit cumbersome to write and messes up the code.
So now I tend to use:
doIf :: Monad a => Bool -> [a b] -> a ()
doIf b e = if b then sequence_ e else return ()
I find the list of computations to be quite flexible and neat. There are
probably plenty of variations on this idea you can try.
Cheers,
Bernie.