Monad Maybe?

Alastair Reid alastair@reid-consulting-uk.ltd.uk
24 Sep 2002 17:28:18 +0100


Hal Daume <hdaume@ISI.EDU> writes:
> I know this has been written about way too much, but I was wondering
> what people thought about using 'liftM f' as opposed to '>>= return . f'.
> I would probably have written Andrew's code using liftM, but
> I don't know if one is necessarily better than the other.  Does
> anyone have strong thoughts on this?

I tend to use liftM only as part of a pattern of lifting a family of
non-monadic functions up to the monadic level in code like this:

  instance (Monad m, Num a) => Num (m a) where
    (+) = liftM2 (+)
    (-) = liftM2 (-)
    negate = liftM1 negate 
    ...

  instance (Monad m, Integral a) => Integral (m a) where
    ...

If it doesn't feel like lifting and/or it isn't part of a pattern like
the above, I tend not to use it.

A