From e285e81c2519dfe9b000d0f297b72c6c9909662d Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Fri, 8 Aug 2014 14:37:06 +0800 Subject: Last few chapters in LYHGG --- stateful.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 stateful.hs (limited to 'stateful.hs') 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 -- cgit v1.2.3-70-g09d2