[Haskell-cafe] Why the reluctance to introduce the Functor requirement on Monad?
Felipe Almeida Lessa
felipe.lessa at gmail.com
Thu Jul 21 14:58:25 CEST 2011
On Thu, Jul 21, 2011 at 8:31 AM, Ivan Lazar Miljenovic
<ivan.miljenovic at gmail.com> wrote:
> Well, for fmap vs liftM, you have that liftM is automatically defined
> for you rather than needing to make the Functor instance, so if you're
> quickly defining a Monad for internal use then you can just use liftM,
> etc. without needing to also make Functor and Applicative instances
> (note that AFAIK, return and pure are the same thing, in that return
> isn't automatically defined like liftM is).
Note that even if we had "class Applicative m => Monad m where ...",
we could say
data X a = ...
instance Functor X where
fmap = liftM
instance Applicative X where
pure = return
(<*>) = ap
instance Monad X where
return = ...
x >>= f = ...
So you just need five more lines of boilerplate to define both Functor
and Applicative.
Cheers,
--
Felipe.
More information about the Haskell-Cafe
mailing list