Signature of Control.Monad when and unless

I understand why the normal signature is: when :: Monad m => Bool -> m () -> m () unless :: Monad m => Bool -> m () -> m () But why isn't there also: when_ :: Monad m => Bool -> m a -> m () unless_ :: Monad m => Bool -> m a -> m () That is, I agree that results shouldn't be discarded "by default", but it should be easy to get rid of them if they are unneeded. Thanks, Oren Ben-Kiki

Hasn't `void` recently been added to Base so that you can discard the result of any monadic action?
when True (void actionWithAnswer)
On 24 August 2012 10:12, Oren Ben-Kiki
That is, I agree that results shouldn't be discarded "by default", but it should be easy to get rid of them if they are unneeded.

On 24 August 2012 22:24, Stephen Tetley
Hasn't `void` recently been added to Base so that you can discard the result of any monadic action?
when True (void actionWithAnswer)
I also recall a similar discussion within the past six months on this topic, though I'm having difficulty finding it either online or in my emails :/ I believe the consensus of the previous discussion was that having functions such as your stated when_ and unless_ are dangerous in the general case due to the discarded results being implicitly ignored (same as how GHC nowadays throws warnings when statements in a do-block aren't of type m () ).
On 24 August 2012 10:12, Oren Ben-Kiki
wrote: [CUT] That is, I agree that results shouldn't be discarded "by default", but it should be easy to get rid of them if they are unneeded.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

On Fri, Aug 24, 2012 at 2:48 PM, Ivan Lazar Miljenovic wrote:
On 24 August 2012 22:24, Stephen Tetley wrote:
Hasn't `void` recently been added to Base so that you can discard the result of any monadic action?
when True (void actionWithAnswer)
I also recall a similar discussion within the past six months on this topic, though I'm having difficulty finding it either online or in my emails :/
It started in April. The thread is split between haskell@ and libraries@: http://www.haskell.org/pipermail/haskell/2012-April/date.html#23276 http://www.haskell.org/pipermail/libraries/2012-April/date.html#17722 Regards, Sean

Personally, I would really like to see these added.
Alas, I missed the discussion the first time around, and I'm afraid if I
tried to raise the issue again the safety police will go through and
actively remove the 'a's from the remaining useful combinators I still
have. ;)
I do find it particularly obnoxious that I have to round trip through the
monad transformer stack just to rip off a type argument when couldn't use
if it wanted to in the first place.
Moreover, the 'void' type that actually wound up implemented doesn't help
at all if you only know you have a Monad and don't have the additional
Functor, (e.g. are writing a monad transformer), so even though void exists
you wind up having to use 'do x <- ...; return ()' in most library code
anyways.
-Edward
On Fri, Aug 24, 2012 at 5:12 AM, Oren Ben-Kiki
I understand why the normal signature is:
when :: Monad m => Bool -> m () -> m () unless :: Monad m => Bool -> m () -> m ()
But why isn't there also:
when_ :: Monad m => Bool -> m a -> m () unless_ :: Monad m => Bool -> m a -> m ()
That is, I agree that results shouldn't be discarded "by default", but it should be easy to get rid of them if they are unneeded.
Thanks,
Oren Ben-Kiki
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On 24.08.12 3:22 PM, Edward Kmett wrote:
Personally, I would really like to see these added.
+1
Alas, I missed the discussion the first time around, and I'm afraid if I tried to raise the issue again the safety police will go through and actively remove the 'a's from the remaining useful combinators I still have. ;)
In the mentioned discussion, I proposed to generalize the types of when and unless to when :: Monad m => Bool -> m a -> m () unless :: Monad m => Bool -> m a -> m () which amounts to implement e.g. when by when True m = m >> return () when False m = return () My proposal triggered an outcry by the `safety community' and I dropped it. It seems that adding when_ and unless_ seems to be a compromise everyone can live with. Cheers, Andreas
I do find it particularly obnoxious that I have to round trip through the monad transformer stack just to rip off a type argument when couldn't use if it wanted to in the first place.
Moreover, the 'void' type that actually wound up implemented doesn't help at all if you only know you have a Monad and don't have the additional Functor, (e.g. are writing a monad transformer), so even though void exists you wind up having to use 'do x <- ...; return ()' in most library code anyways.
-Edward
On Fri, Aug 24, 2012 at 5:12 AM, Oren Ben-Kiki
mailto:haskell-oren@ben-kiki.org> wrote: I understand why the normal signature is:
when :: Monad m => Bool -> m () -> m () unless :: Monad m => Bool -> m () -> m ()
But why isn't there also:
when_ :: Monad m => Bool -> m a -> m () unless_ :: Monad m => Bool -> m a -> m ()
That is, I agree that results shouldn't be discarded "by default", but it should be easy to get rid of them if they are unneeded.
Thanks,
Oren Ben-Kiki
-- Andreas Abel <>< Du bist der geliebte Mensch. Theoretical Computer Science, University of Munich Oettingenstr. 67, D-80538 Munich, GERMANY andreas.abel@ifi.lmu.de http://www2.tcs.ifi.lmu.de/~abel/
participants (6)
-
Andreas Abel
-
Edward Kmett
-
Ivan Lazar Miljenovic
-
Oren Ben-Kiki
-
Sean Leather
-
Stephen Tetley