Combining IO and state monads
Derek Elkins
ddarius@hotpop.com
Sun, 18 May 2003 17:54:15 -0400
On Fri, 16 May 2003 14:51:19 +0100
Graham Klyne <GK@ninebynine.org> wrote:
> This may be a very dumb question, but...
>
> I've been digging around Monad transformers, trying to get the feel of
> how to use them. In part, I'm referring to the library source code,
> and come across the following in Control.Monad.State, which I'm having
> trouble figuring out:
>
> [[
> -- MonadState class
> --
> -- get: returns the state from the internals of the monad.
> -- put: changes (replaces) the state inside the monad.
>
> class (Monad m) => MonadState s m | m -> s where
> get :: m s
> put :: s -> m ()
> ]]
>
> What does the vertical bar "|" in the class declaration mean? I can't
> find this use mentioned in the Haskell report or the GHC type system
> extensions.
It's mentioned in GHC's type extensions, but only as a reference to a
paper. The '| m -> s' is a functional dependency. You could certainly
use MonadState without even knowing about it, all you really need to
know is what get and put do and that's fairly straightforward.