
Iavor Diatchki wrote:
*> when :: Monad m => m a -> Bool -> m (Maybe a)
I am not sure if this would be useful. If you cared about the result you would have to write: do { x <- when p m; case x of { Just a -> e1; Nothing -> e2. }
...unless you wanted the result in the form of a Maybe. Since there really is no other sensible choice for the "False" branch, I contend that _if_ you want the result at all, you want is as a maybe. If not, well, then ignoring (Maybe a) isn't any harder than ignoring (); (>>) already accomplishes that.
A simpler and (probably) more efficient way to write the above is: do { if p then do { a <- m; e1} else e2 }
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
The main point of this discussion has been: (i) Should the ignoring be done silently in the library, or (ii) should the programmer be explicit (i.e., write 'm >> return ()').
I just think that both options are wrong. (iii) should the programmer be explicit (ie. write 'when p m >>') Udo. -- Das Elend hat viele Gesichter, wie gefällt Ihnen meins?