<div dir="auto">The symmetry appeals to me. However, `when` is mostly for convenience: I mostly use it to reduce indentation in `do` notation. I don't see where I would find `mwhen` particularly convenient. So -0.5 from me for now, but I could be swayed by more persuasive examples.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 10, 2019, 11:36 AM James Ashwell <<a href="mailto:james.michael.ashwell@gmail.com">james.michael.ashwell@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-GB" link="blue" vlink="#954F72"><div class="m_4690446268135818487WordSection1"><p class="MsoNormal">This would mimic the behaviour of <span style="font-family:"Courier New"">Control.Monad.when</span> for monoids rather than applicatives.<u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Courier New"">mwhen :: Monoid m => Bool -> m -> m<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">mwhen b a<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New""> | b = a<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New""> | otherwise = mempty<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">-- </span>Examples:<span style="font-family:"Courier New""><u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">when :: Applicative f => Bool -> f () -> f ()<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">when b = getAp . mwhen b . Ap<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">-- mwhen b = getConst . when b . Const<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">guard :: Alternative f => Bool -> f ()<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">guard b = getAlt (mwhen b (pure ()))<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">applyIf :: Bool -> (a -> a) -> (a -> a)<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">applyIf b = appEndo . mwhen b . Endo<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">-- </span>Using<span style="font-family:"Courier New""> Monoid m => Monoid (a -> m)<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">-- mwhen b f x = if b then f x else mempty = mwhen b (f x)<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">-- mwhen b f x y = if b then f x y else mempty = mwhen b (f x y)<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">-- </span>etc<u></u><u></u></p><p class="MsoNormal"><span style="font-family:"Courier New""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Courier New"">-- mwhen b x <> y = if b then x <> y else y<u></u><u></u></span></p></div></div>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>