Commit 2a87f6f1 authored by Erin van der Veen's avatar Erin van der Veen

Implement Stack datastructure

parent 4f8bedda
definition module Data.Stack
from Data.Maybe import :: Maybe
from StdOverloaded import class length
:: Stack a = Stack [a]
newStack :: Stack a
empty a :== case q of
Stack [] -> True
_ -> False
instance length Stack
// Add element to the 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)
implementation module Data.Stack
import Data.Maybe
import StdList, StdOverloaded
newStack :: Stack a
newStack = Stack []
instance length Stack
length Stack a = length a
push :: a (Stack a) -> (Stack a)
push a as = [a : as]
pop :: (Stack a) -> (Maybe a, Stack a)
pop (Stack []) = (Nothing, newStack)
pop (Stack [a : as]) = (Just a, Stack as)
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