The original question
Recent version(s) of Haskell (> 7.4.2?) come with an mtl package that no longer provides a State constructor per se, instead providing a state function.
This messes up the examples of State in the wikibooks page here: http://en.wikibooks.org/wiki/Haskell/Understanding_monads/State
Could someone show how to revise the example following heading "Introducing State"? That's the small functions rollDie and rollDice.
There's a Note box earlier on the page, near heading "Definition of the State Monad" which describes in general what to do, but it's too vague for me.
Also, I'm not quite clear on how imports and packages work, so a possible related thing critical to this example may be specifying what imports are needed, as they too may have changed.
Thanks!
Source code
------- Adding code for ghci01.hs-------
-- http://en.wikibooks.org/wiki/Haskell/Understanding_monads/State
-- Introducing State heading and below
import Control.Monad
import System.Random
type GeneratorState = State StdGen
rollDie :: GeneratorState Int
rollDie = do generator <- get
let (value, newGenerator) = randomR (1,6) generator
put newGenerator
return value
-- Test rollDie
-- evalState rollDie (mkStdGen 0)
rollDice :: GeneratorState (Int, Int)
rollDice = liftM2 (,) rollDie rollDie
-- Test rollDice
-- evalState rollDice (mkStdGen 666)
------- In GHCi --------
ghci> :l dice01.hs
[1 of 1] Compiling Main ( dice01.hs, interpreted )
dice01.hs:7:23: Not in scope: type constructor or class `State'
dice01.hs:10:27: Not in scope: `get'
dice01.hs:12:14: Not in scope: `put'
Failed, modules loaded: none.
Addendum
For others who stumble in here:
The main topic of this question revolves around the non-working example code, and the warning in the Note box on the wikibooks page referenced above. That box tells that for MTL version > 2.0.0.0, some of the example code won't work due to change in Control.Monad.State.
My test involved Haskell Platform 2012.4.0.0, which includes GHC 7.4.2, and MTL which I belatedly discovered to be 1.1.1.1, based on the mtl.cabal file. So, the Note's warning should not apply, but nonethless the example code did not work. The change recommended by answers here (change import Control.Monad to Control.Monad.State) did fix the problem. But evidently that was fixing a problem that pertained to some earlier change, not to the MTL 2.x referenced in the Note.
I've since looked at the source for GHC 7.6.2, and there I don't find an MTL library at all. Instead the State-related files are in libraries/transformers/Control/Monad/Trans/State. I then took a bunch of confusing detours, including the problem that currently there is no Haskell Platform that uses GHC later than 7.4.2 (ie: no 7.6.2).
Then I found the MTL docs (http://www.haskell.org/haskellwiki/Monad_Transformer_Library) which point to this stackoverflow Q&A: mtl, transformers, monads-fd, monadLib, and the paradox of choice ... which sort of explains a lot, at least as of 2-3 years ago.