Stack.dcl 592 Bytes
Newer Older
1 2 3 4 5 6
definition module Data.Stack
from Data.Maybe import :: Maybe
from StdOverloaded import class length

:: Stack a = Stack [a]

Camil Staps's avatar
Camil Staps committed
7 8 9
/**
 * Create a new, empty Stack.
 */
10 11
newStack :: Stack a

Camil Staps's avatar
Camil Staps committed
12 13 14 15
/**
 * Check whether a Stack is empty.
 * @type (Stack a) -> Bool
 */
16
empty a :== case a of
17 18 19 20 21
	Stack [] -> True
	_	 -> False

instance length Stack

Camil Staps's avatar
Camil Staps committed
22 23 24
/**
 * Add an element to the Stack.
 */
25
push :: a (Stack a) -> Stack a
26

Camil Staps's avatar
Camil Staps committed
27 28 29
/**
 * Remove element from the Stack and return it if the Stack is not empty.
 */
30 31
pop :: (Stack a) -> (Maybe a, Stack a)

Camil Staps's avatar
Camil Staps committed
32 33 34
/**
 * Peek the top of the Stack.
 */
35
peek :: (Stack a) -> Maybe a