We planned to upgrade GitLab and Mattermost to the latest version this Friday morning (early). You may experience some downtime!

Commit c135690a authored by Erin van der Veen's avatar Erin van der Veen

Fix FIFO typo. Implement peek for Stack

parent 2a87f6f1
......@@ -6,7 +6,7 @@ from StdOverloaded import class length
newStack :: Stack a
empty a :== case q of
empty a :== case a of
Stack [] -> True
_ -> False
......@@ -16,4 +16,8 @@ instance length Stack
push :: a (Stack a) -> (Stack a)
// Remove element from the Stack and return it if the Stack is not empty
pop :: (Stack a) -> (Maybe a, LIFO a)
pop :: (Stack a) -> (Maybe a, Stack a)
// Peek the top of the Stack
peek :: (Stack a) -> (Maybe a)
......@@ -7,11 +7,15 @@ newStack = Stack []
instance length Stack
where
length Stack a = length a
length (Stack a) = length a
push :: a (Stack a) -> (Stack a)
push a as = [a : as]
push a (Stack as) = Stack [a : as]
pop :: (Stack a) -> (Maybe a, Stack a)
pop (Stack []) = (Nothing, newStack)
pop (Stack [a : as]) = (Just a, Stack as)
peek :: (Stack a) -> (Maybe a)
peek (Stack []) = Nothing
peek (Stack [a : as]) = Just a
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment