Signature of Control.Monad when and unless
Andreas Abel
andreas.abel at ifi.lmu.de
Sun Aug 26 11:50:39 CEST 2012
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
> <haskell-oren at ben-kiki.org <mailto:haskell-oren at 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 at ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/
More information about the Libraries
mailing list