Keith Sheppard keithshep at gmail.com
Tue Jun 22 21:53:14 EDT 2010

Hi,

I'm working on understanding the state monad, and I got stumped pretty
much right away. When I run the following script (with instances
copied verbatim from

\begin{code}
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}

newtype State s a = State { runState :: (s -> (a,s)) }

return a        = State $\s -> (a,s) (State x) >>= f = State$ \s -> let (v,s') = x s in runState (f v) s'

instance MonadState (State s) s where
get   = State $\s -> (s,s) put s = State$ \_ -> ((),s)

main :: IO ()
main = putStrLn "hello"

\end{code}

It fails with:
State s' is not applied to enough type arguments
Expected kind *', but State s' has kind * -> *'
In the instance declaration for MonadState (State s) s'

Can you see what I'm doing wrong? I must be making a really basic
mistake but I'm not sure what it is.

Thanks, Keith
--
keithsheppard.name
`