Stack-0.2.0: Stack data structure type

Safe HaskellSafe
LanguageHaskell2010

Data.Stack

Description

Synopsis

Documentation

data Stack a Source #

Abstract Stack data type

Instances

Read a => Read (Stack a) Source # 
Show a => Show (Stack a) Source # 

Methods

showsPrec :: Int -> Stack a -> ShowS #

show :: Stack a -> String #

showList :: [Stack a] -> ShowS #

stackNew :: Stack a Source #

Create new Stack

stackPush :: Stack a -> a -> Stack a Source #

Push item onto Stack

(∀x)(∀s)(stackPop (stackPush s x) == Just (s,x))

stackPeek :: Stack a -> Maybe a Source #

Pop most recently added item without removing from the Stack

stackPeek stackNew == Nothing
(∀x)(∀s)(stackPeek (stackPush s x) == Just x)
(∀s)(stackPeek s == fmap snd (stackPop s))

stackPop :: Stack a -> Maybe (Stack a, a) Source #

Pop most recently added item from Stack

stackPop stackNew == Nothing
(∀x)(∀s)(stackPop (stackPush s x) == Just (s,x))

stackIsEmpty :: Stack a -> Bool Source #

Test if stack is empty

stackIsEmpty stackNew == True
(∀x)(∀s)(stackIsEmpty (stackPush s x) == True)
(∀s)((stackSize s == 0) ⇔ (stackIsEmpty s == True))

stackSize :: Stack a -> Int Source #

Compute number of elements contained in the Stack

stackSize stackNew == 0
(∀x)(∀s)((stackSize s == n) ⇒ (stackSize (stackPush s x) == n+1))