diff options
Diffstat (limited to 'stateful.hs')
-rw-r--r-- | stateful.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/stateful.hs b/stateful.hs new file mode 100644 index 0000000..63548d3 --- /dev/null +++ b/stateful.hs @@ -0,0 +1,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 |