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

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

On 25/07/2013 20:16, John Wiegley wrote:
The function is:
om f m = (m >>=) . flip f [...] 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.
I have to admit my first reaction to this was that it isn't April 1st... More seriously, "om" sounds useful but the name seems a bit obscure ("on monad"?) Are there any examples of "nom" being useful? Cheers, Ganesh

Are there any examples of "nom" being useful?
I find 'nom' to be useful if defined as "const id":
-- Given 'om'
om f m = (m >>=) . flip f
-- And 'nom'
nom = const id
-- And the natural name for a monadic version of 'no'thing
noM = return ()
-- We construct a useful example of 'nom':
eatCookies :: IO ()
eatCookies = om nom noM noM
:-)
Happy Friday,
Greg
On Thu, Jul 25, 2013 at 2:21 PM, Ganesh Sittampalam
On 25/07/2013 20:16, John Wiegley wrote:
The function is:
om f m = (m >>=) . flip f [...] 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.
I have to admit my first reaction to this was that it isn't April 1st...
More seriously, "om" sounds useful but the name seems a bit obscure ("on monad"?) Are there any examples of "nom" being useful?
Cheers,
Ganesh
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Fri, 26 Jul 2013, Greg Fitzgerald wrote:
Are there any examples of "nom" being useful?
I find 'nom' to be useful if defined as "const id":
-- Given 'om' om f m = (m >>=) . flip f
-- And 'nom' nom = const id
-- And the natural name for a monadic version of 'no'thing noM = return ()
-- We construct a useful example of 'nom': eatCookies :: IO () eatCookies = om nom noM noM
So far I was not convinced by the proposal. But this one seems to be really useful and a real world application!

On 26.07.13 9:40 PM, Henning Thielemann wrote:
-- We construct a useful example of 'nom': eatCookies :: IO () eatCookies = om nom noM noM
So far I was not convinced by the proposal. But this one seems to be really useful and a real world application!
Fantastic! That will make Haskell programming sweeter, while still a bit dry. Maybe we should have some Java with it. -- 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/

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
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@haskell.org http://www.haskell.org/mailman/listinfo/libraries
participants (6)
-
Andreas Abel
-
Edward Kmett
-
Ganesh Sittampalam
-
Greg Fitzgerald
-
Henning Thielemann
-
John Wiegley