summaryrefslogtreecommitdiff
path: root/miralib/ex/stack.m
diff options
context:
space:
mode:
Diffstat (limited to 'miralib/ex/stack.m')
-rw-r--r--miralib/ex/stack.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/miralib/ex/stack.m b/miralib/ex/stack.m
new file mode 100644
index 0000000..d7a1af2
--- /dev/null
+++ b/miralib/ex/stack.m
@@ -0,0 +1,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))