I'm trying to run one of the most simple examples from the Haskell online book where you implement a stateful function modeling a stack of numbers. The code from the example I'm using is (http://learnyouahaskell.com/for-a-few-monads-more#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)
Yet when trying to load it in Prelude I get:
state.hs:6:7: error:
Data constructor not in scope:
State :: ([a0] -> (a0, [a0])) -> State Stack Int
|
6 | pop = State $ \(x:xs) -> (x,xs)
| ^^^^^
state.hs:9:10: error:
Data constructor not in scope:
State :: ([Int] -> ((), [Int])) -> State Stack ()
|
9 | push a = State $ \xs -> ((),a:xs)
| ^^^^^
Failed, no modules loaded.
What am I missing??? Is this example somehow wrong?
I was just expecting to simply load the module with no errors. No clue what is wrong.