concrete functor and monad transformers
#50Does `Applicative (MaybeT m)` really need the `Monad` constraint?
Basically, instead of the existing Applicative
implementation for MaybeT
that relies on >>=
and return
, I think it could be defined as such:
instance (Applicative m) => Applicative (MaybeT m) where
pure = MaybeT . pure . Just
mf <*> mx = let f = fmap (<*>) (runMaybeT mf) in MaybeT $ f <*> runMaybeT mx
I think the same goes for a few others as well (eg, EitherT
). But perhaps there is some good reason for using bind/Monad instead?
- description updated
The issue is that when an
Applicative
is also aMonad
,(<*>)
needs to be the same asap
. With the monadic version, if the first argument yieldsNothing
, the second second is not executed, whereas with the above version it would be.Ah, right, that makes perfect sense. Thanks for the explanation!
- status set to closed