[Haskell-cafe] fmap vs. liftM

Derek Elkins derek.a.elkins at gmail.com
Mon Feb 4 11:32:08 EST 2008


On Mon, 2008-02-04 at 12:22 -0200, Felipe Lessa wrote:
> Hi there,
> 
> Reading http://www.haskell.org/haskellwiki/Things_to_avoid I found an
> interesting saying:
> 
> "By the way, in the case of IO monad the Functor class method fmap and
> the Monad based function liftM are the same."
> 
> I always tought that
> 
> prop :: (Functor m, Monad m, Eq (m b)) => (a -> b) -> m a -> Bool
> prop f x = fmap f x == liftM f x
> 
> was True regardless of 'm'. Is there any exception?

If there is, it's a bug in the library except you wouldn't normally use
(==) but some meta-level equality*.  From one perspective, liftM is the
proof that every monad is a functor. 

* Usually observational equality, but one may want variants, e.g.
observational equality with respect to some "observe" function



More information about the Haskell-Cafe mailing list