Proposal: Add Chris Done's "om" combinator to Control.Monad

Edward Kmett ekmett at gmail.com
Fri Jul 26 06:51:57 CEST 2013


I'm -1 on this just because it is a rather awkward idiom to use, the name
doesn't really make much sense and it is less fundamental than many of the
things we've rejected on those grounds in the past. ;)

-Edward

On Thu, Jul 25, 2013 at 3:16 PM, John Wiegley <johnw at fpcomplete.com> wrote:

> The function is:
>
>     om f m = (m >>=) . flip f
>
> Allowing this typical usage:
>
>     om when (return True) $
>         print "Hello"
>
> Thus, it allows one to do away with the monadic variants of pure functions,
> such as "whenM", "unlessM", etc.:
>
>     whenM   = om when
>     unlessM = om unless
>
> "om" gets even more handy when you want to apply a monadic function to a
> monadic value in yet another monad:
>
>     >>> om for_ (return (Just True)) print
>     True
>
> Rather than the typical (which I must have written hundreds of times by
> now):
>
>     mx <- return (Just x)
>     for_ mx $ \x -> {- use x... -}
>
>
> A rider to this proposal is to also add "nom = flip om", but I can live
> without that one.  "om", however, is handy enough that I've started locally
> defining in all the modules where I find myself now reaching for it.
>
> --
> John Wiegley
> FP Complete                         Haskell tools, training and consulting
> http://fpcomplete.com               johnw on #haskell/irc.freenode.net
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20130726/985fc9fe/attachment.htm>


More information about the Libraries mailing list