
I am trying to come to grips with the state monad and as a starting point I copied the some code directly from the book Learn You a Haskell for Great Good then added the type synonym for Stack import Control.Monad.State type Stack = [Int] pop :: State Stack Int pop = State $ \(x:xs) -> (x,xs) push :: Int -> State Stack () push a = State $ \xs -> ((),a:xs) However, attempting to load this into ghci produces the errors stackPlay.hs:6:7: Not in scope: data constructor `State' stackPlay.hs:9:10: Not in scope: data constructor `State' Please excuse the cognitive deficit, but I cannot figure out why this should not work as advertised. ::paul

I believe that the type constructor for State is now lowercase: "state" not "State". import Control.Monad.State type Stack = [Int] pop :: State Stack Int pop = state $ \(x:xs) -> (x,xs) push :: Int -> State Stack () push a = state $ \xs -> ((),a:xs) play = do push 1 push 2 push 3 pop main = print $ runState play [] L. On Sun, Apr 22, 2012 at 01:40:17AM -0700, Paul Higham wrote:
I am trying to come to grips with the state monad and as a starting point I copied the some code directly from the book Learn You a Haskell for Great Good then added the type synonym for Stack
import Control.Monad.State
type Stack = [Int]
pop :: State Stack Int pop = State $ \(x:xs) -> (x,xs)
push :: Int -> State Stack () push a = State $ \xs -> ((),a:xs)
However, attempting to load this into ghci produces the errors
stackPlay.hs:6:7: Not in scope: data constructor `State'
stackPlay.hs:9:10: Not in scope: data constructor `State'
Please excuse the cognitive deficit, but I cannot figure out why this should not work as advertised.
::paul
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Lorenzo Bolla http://lbolla.info

On Sun, Apr 22, 2012 at 04:40, Paul Higham
stackPlay.hs:6:7: Not in scope: data constructor `State'
Please excuse the cognitive deficit, but I cannot figure out why this should not work as advertised.
Not your fault; things were rearranged in the library, and `State` is no longer a distinct type (it's `StateT Identity` now). `state` (lowercase) is the replacement for the old `State` constructor. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (3)
-
Brandon Allbery
-
Lorenzo Bolla
-
Paul Higham