[Haskell-cafe] Newbie: State monad example questions

Jules Bean jules at jellybean.co.uk
Wed May 21 11:31:04 EDT 2008


Dmitri O.Kondratiev wrote:
> Jules,
> 
> Stupid question, please bear with me:
> 
> x :: Int -- x declared, but not constructed
> x = 1 -- x constructed
> 
> s1 :: State StdGen a -- s1 declared, yes, but why s1 is *also already 
> constructed* ?

it's not.

it's constructed when you do

s1 = return 1

... or ...

s1 = get >>= put

.. or some other more complex interaction, perhaps using do notation.

It's the >>= or the return that construct the State, just as the '1' is 
enough to construct the Int.

Jules


More information about the Haskell-Cafe mailing list