Hi guys, the way `StateT` are implemented as `Applicative` have been buggling my mind for some time.
instance (Functor m, Monad m) => Applicative (StateT s m) where
pure a = StateT $ \ s -> return (a, s)
StateT mf <*> StateT mx = StateT $ \ s -> do
(f, s') <- mf s
(x, s'') <- mx s'
return (f x, s'')
Using dependant monadic computations, this implementation cannot be expressed in term of applicative.
This explains why we cannot have `instance (Applicative m) => Applicative (State s m)`.
However using real monadic style computations for implementing `<*>` buggles my mind.
Moreover `liftA2 (<*>)` can be used to generically compose applicative functors so why monads are needed?
Any inputs would be greatly appreciated!
Cheers,
Laurent