summaryrefslogtreecommitdiff
path: root/miralib/ex/stack.m
blob: d7a1af27e55f8d284322c76e286bb53dea38b90a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
||This script defines stack, as an abstract data type based on lists.
||Note that there is a show function for stacks, causing them to print
||in a sensible way.

abstype stack *
with empty::stack *; push::*->stack *->stack *;
     pop::stack *->stack *; top::stack *->*; isempty::stack *->bool;
     showstack::(*->[char])->stack *->[char]

stack * == [*]
empty = []
push a x = a:x
pop(a:x) = x
top(a:x) = a
isempty x = (x=[])
showstack f [] = "empty"
showstack f (a:x) = "(push " ++ f a ++ " " ++ showstack f x ++ ")"

teststack = push 1(push 2(push 3 empty))