[Haskell-cafe] Why the reluctance to introduce the Functor requirement on Monad?

Sebastien Zany sebastien at chaoticresearch.com
Sat Jul 23 16:49:50 CEST 2011


Would it be theoretically possible/convenient to be able to put boilerplate
like this in class definitions?


On Thu, Jul 21, 2011 at 5:58 AM, Felipe Almeida Lessa <
felipe.lessa at gmail.com> wrote:

> 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110723/9f856686/attachment.htm>


More information about the Haskell-Cafe mailing list