diff options
author | Joe Zhao <ztuowen@gmail.com> | 2014-08-08 14:37:06 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2014-08-08 14:37:06 +0800 |
commit | e285e81c2519dfe9b000d0f297b72c6c9909662d (patch) | |
tree | 352ee7f112be704111da437df4f62f15a37b3be9 /stateful.hs | |
parent | 423693811904a6038a1a7532700726799e05fade (diff) | |
download | haskbox-old-e285e81c2519dfe9b000d0f297b72c6c9909662d.tar.gz haskbox-old-e285e81c2519dfe9b000d0f297b72c6c9909662d.tar.bz2 haskbox-old-e285e81c2519dfe9b000d0f297b72c6c9909662d.zip |
Last few chapters in LYHGG
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 |