import Control.Monad.State type Stack = [Int] --Define the pop function pop :: Stack -> (Int, Stack) pop (x:xs) = (x, xs) --Define the push function push :: Int -> Stack -> ((), Stack) push x xs = ((), x:xs) stackManip :: Stack -> (Int, Stack) stackManip stack = let (a, stack1) = pop stack (b, stack2) = pop stack1 ((), stack3) = push 100 stack2 (c, stack4) = pop stack3 in pop stack4 popM :: State Stack Int popM = do x:xs <- get put xs return x pushM :: Int -> State Stack () pushM a = do xs <- get put (a:xs) return() stackManipM :: State Stack Int stackManipM = do popM popM pushM 100 popM popM stackStuff :: State Stack () stackStuff = do a <- popM if (a==5) then return () else do pushM 3 pushM 8 get