[Haskell-cafe] Applicative transformers

Laurent Christophe lachrist at vub.ac.be
Wed Feb 15 17:01:37 UTC 2017

Hi guys, the way `StateT` are implemented as `Applicative` have been buggling my mind for some time.
https://hackage.haskell.org/package/transformers- <https://hackage.haskell.org/package/transformers->

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?
https://www.haskell.org/haskellwiki/Applicative_functor#Applicative_transfomers <https://www.haskell.org/haskellwiki/Applicative_functor#Applicative_transfomers>

Any inputs would be greatly appreciated!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170215/df054ec8/attachment.html>

More information about the Haskell-Cafe mailing list