Re: [Haskell] Types of when and unless in Control.Monad

On Sat, 21 Apr 2012, Andreas Abel wrote:
While your comments about not ignoring results of functions may be right, in the particular case of when and unless the situation is different. Since both are basically an if-then without an else, the expression *cannot* yield a result, just execute the monadic effect. Thus, confusion is unlikely.
I don't understand this argument. The current type of 'when' is
when :: (Monad m) => Bool -> m () -> m ()
thus it makes sure, that the enclosed action has no result that could be ignored by accident. If the function would be
when_ :: (Monad m) => Bool -> m a -> m ()
then you could write
when_ b (system "command")
and thus miss the ExitCode of 'system' by accident.
I have defined myself when_ and unless_ but I think it is silly, the library functions could be more general.
Since you think that the current 'when's type is silly, I would like to know what are your examples where you want to ignore the result of the enclosed action?
participants (1)
-
Henning Thielemann