Edward Kmett ekmett at
Wed Jan 26 23:14:11 CET 2011

On Wed, Jan 26, 2011 at 5:00 PM, David Menendez <dave at> wrote:

> On Wed, Jan 26, 2011 at 3:56 PM, Edward Kmett <ekmett at> wrote:
> > Fair enough.
> > These are the observations I have about 'transformers'.
> > 2.) The instance for Applicative for MaybeT doesn't really follow the
> other
> > instances for Applicative in transformers.
> > instance Applicative m => Applicative (MaybeT m) where
> >    pure = MaybeT . pure . Just
> >    f <*> a = MaybeT $ (<*>) <$> runMaybeT f <*> runMaybeT a
> > would instead follow the convention that Applicatives depend only on
> > Applicatives where possible, as opposed to the current default instance.
> > This convention is followed everywhere in transformers except this
> module.
> Then you no longer have (<*>) = ap.
> This convention is also not followed for the StateT and ErrorT
> transformers for the same reason.
> If you want something like MaybeT f whose Applicative instance depends
> only on the Applicative instance of f, try Compose f Maybe.

By that reasoning the existing Applicative instances for WriterT and ListT
would be wrong in mtl as well.

StateT actually requires a monad, because the s -> m (a, s) monad is given
rise to by sandwiching a monad in an adjunction, which isn't sufficient to
 yield an Applicative instance, but the ErrorT and MaybeT can both perfectly
well get by on the weaker Applicative requirement, because they simply

The consistency of ap and (<*>) is assumed universally. Applicative merely
allows you to optimize this case.

-Edward Kmett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list