[Haskell-cafe] instance Applicative f => Applicative (StateT s f)
Thomas Davie
tom.davie at gmail.com
Fri Dec 5 12:56:46 EST 2008
>
> That would be incompatible with the ap of the monad where it exists,
> but it's worse than that. Which state will you return? If you return
> one of the states output by one or other of the arguments, you'll
> break
> one of the laws:
>
> pure id <*> v = v
> u <*> pure y = pure ($ y) <*> u
>
> You're forced to return the input state, so the Applicative would just
> be an obfuscated Reader.
Which reminds me ofc, that there is a valid applicative for states
(assuming the monad instance is valid):
instance Applicative (StateT s f) where
pure = return
(<*>) = ap
All monads are also applicatives ;)
Bob
More information about the Haskell-Cafe
mailing list