lab08: init

This commit is contained in:
2026-03-02 11:14:28 -08:00
parent 23b2a4376d
commit 70c88a8ba2
6 changed files with 187 additions and 0 deletions

29
lab08/stack.hs Normal file
View File

@@ -0,0 +1,29 @@
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'