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 <
[email protected]> wrote:

> On Thu, Jul 21, 2011 at 8:31 AM, Ivan Lazar Miljenovic
> <[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to