[Haskell-beginners] state monad

Paul Higham polygame at mac.com
Sun Apr 22 10:40:17 CEST 2012

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.


More information about the Beginners mailing list