module Data.Stack (
Stack,
stackNew,
stackIsEmpty,
stackPush,
stackPeek,
stackPop,
stackSize,
)
where
data Stack a = Stack [a] deriving (Read,Show)
stackNew :: Stack a
stackNew = Stack []
stackIsEmpty :: Stack a -> Bool
stackIsEmpty (Stack []) = True
stackIsEmpty (Stack _) = False
stackPush :: Stack a -> a -> Stack a
stackPush (Stack items) item = Stack (item : items)
stackPeek :: Stack a -> a
stackPeek (Stack items) = head items
stackPop :: Stack a -> (Stack a, a)
stackPop (Stack items) = (Stack (tail items), stackPeek (Stack items))
stackSize :: Stack a -> Int
stackSize (Stack items) = length items