[Haskell-cafe] fmap vs. liftM

Henning Thielemann lemming at henning-thielemann.de
Tue Feb 5 08:31:57 EST 2008


On Mon, 4 Feb 2008, Miguel Mitrofanov wrote:

> > Problem is that from the idea Functor is a superclass of Monad, with
> > the
> > property that "fmap == liftM".
>
> [cut]
>
> > The second relation can even not be expressed in Haskell 98.
>
> Erm...
>
> class Functor f where
>      fmap :: (a -> b) -> f a -> f b
> class Functor m => Monad m where
>      return :: a -> m a
>      join :: m (m a) -> m a
>
> bind :: Monad m => m a -> (a -> m b) -> m b
> bind mx f = join $ fmap f mx

nice

> Now liftM must be exactly equal to fmap.

How do you convince the compiler that
  'join (fmap return x) == x' ?


More information about the Haskell-Cafe mailing list