[Haskell-beginners] Control.Monad.State: State CTOR unneeded to create a State?

Brent Yorgey byorgey at seas.upenn.edu
Sat Nov 1 15:43:55 EDT 2008


On Sat, Nov 01, 2008 at 11:23:38AM -0500, Larry Evans wrote:
>
>  put (n+1)
> AFAICT, with the preceding |n <- get|, this means:
>
>  put (get+1)
> and since the get has type, |State Int Int|, and there's
> not + operator defined on that type (because the following:
>

Others have explained in more detail, let me just state this simply to
hopefully clear up the main point of confusion:

  let x = y

    and

  x <- y

are *not* the same.  In the first case, x is just a name for y, and x
and y can be used interchangeably.  In the second case, x is bound to
*the result of* the action y.  So x and y cannot be used
interchangeably.

-Brent


More information about the Beginners mailing list