So you flipped the elements of the pair in your definition of return from (x,st) to (st,x).

But look at your newtype:s->(a,s) becomes a->(a,s). /Everything else/ stays the same, including the order of your (State s a) parameters. Does that help?

Another hint: what do you think the (type!) variables "a" and "s" stand for?

-- Kim-Ee



On Fri, Dec 7, 2012 at 7:06 AM, Ezequiel Hernan Di Giorgi <hernan.digiorgi@gmail.com> wrote:
this code compiles correcly:

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

instance Monad (State s) where
  --return :: a -> State s a
    return x = State (\st -> (x,st))

but this one doesn't compile:

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

instance Monad (State s) where
  --return :: a -> State s a
    return x = State (\st -> (st,x))

Why is this happening?
 

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners