[Haskell-cafe] Stacking monads
Robert Greayer
robgreayer at yahoo.com
Thu Oct 2 16:36:52 EDT 2008
--- On Thu, 10/2/08, Andrew Coppin <andrewcoppin at btinternet.com> wrote:
> I'm lost...
>
> (What does liftM have to do with fmap?)
They're (effectively) the same function.
i.e.
liftM :: (Monad m) => (a -> b) -> m a -> m b
fmap :: (Functor f) => (a -> b) -> f a -> f b
liftM turns a function from a to b into a function from m a to m b;
fmap turns a function from a to b into a function from f a to f b;
If your datatype with a Monad instance also has a Functor instance (which it *can* have, you just need to declare the instance), then liftM is equivalent to fmap.
More information about the Haskell-Cafe
mailing list