[Haskell-beginners] State Monad - Not in scope: data constructor `State'

Hugo Ferreira hmf at inescporto.pt
Sat Oct 29 21:48:28 CEST 2011


Hello,

I am trying to use some State Monad code
in order to learn about this. However in
GHCi I cannot use the "State" constructor.

import qualified Control.Monad.State

 >:{
| let fromStoAandS c | c `mod` 5 == 0 = ("foo",c+1)
|                | otherwise      = ("bar",c+1)
| :}
 > :t fromStoAandS
 >fromStoAandS :: Integral t => t -> ([Char], t)

 >:{
| let stateIntString = State fromStoAandS
 >Prelude Control.Monad.State| :}
 >
 ><interactive>:1:22: Not in scope: data constructor `State'

I have found a message stating that this is not possible
because their is "no State data constructor", it is only "defined
to be a type alias". The author of the message then says we should use:

http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-State-Lazy.html#v:state

instead. Still lost however.
So, how do I create the "Sate" above?

TIA,
Hugo F.




More information about the Beginners mailing list