Files
cs-252/lab08/stack.hs
2026-03-05 23:06:34 -08:00

30 lines
518 B
Haskell

import Control.Monad.State
type Stack = [Int]
pop :: Stack -> (Int,Stack)
pop (x:xs) = (x,xs)
push :: Int -> Stack -> ((),Stack)
push a xs = ((),a:xs)
stackManip :: Stack -> (Int, Stack)
stackManip stack = let
((),newStack1) = push 3 stack
(a ,newStack2) = pop newStack1
in pop newStack2
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
a <- pop'
pop'