summaryrefslogtreecommitdiff
path: root/stateful.hs
blob: 63548d3e6dd4ea210c3ed0758a94182ea53e86c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)

stackManip :: State Stack Int
stackManip = do
    push 3
    pop
    pop