I wonder if Applicative is derived naturally through MonadTransformer's Monad
I had a hard time finding out if MaybeT's Monad and Applicative have the same context. As you can see in the link above.
The meaning of "same context" is
f <*> a = do
x <- f
y <- a
return (x y)
I found a counter-example for MaybeT.
f = MaybeT [Nothing] :: MaybeT [] (Int -> Int)
a = MaybeT [Just 1, Just 2, Nothing] :: MaybeT [] Int
f <*> a = [Nothing, Nothing, Nothing]
do
x <- f
y <- a
return (x y)
= [Nothing]
So, it seems like there's a discord in MaybeT's Applicative and Monad.
How could we mix up >> , > , >>= . (<>) if there is a discord?
I can't believe it. If there is such a discrepancy, shouldn't there be a bug in the many Haskell codes currently using MaybeT?
As mentioned in the comments, the question has a false premise. The two expressions in the question,
and
both produce the same result,
MaybeT [Nothing].You shouldn't be able to find examples in the wild where these two expressions differ for a single type. One of the laws listed in the Monad class is
which is just a desugaring of the identity you're trying to disprove. There are probably some examples out there of monads that break this law, but they're not "supposed" to.