[Haskell-beginners] (:

Kim-Ee Yeoh ky3 at atamo.com
Fri Dec 7 03:17:20 CET 2012


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 at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121207/b57449f3/attachment.htm>


More information about the Beginners mailing list