summaryrefslogtreecommitdiffstats
path: root/stdlib/stack.ml
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/stack.ml')
-rw-r--r--stdlib/stack.ml18
1 files changed, 18 insertions, 0 deletions
diff --git a/stdlib/stack.ml b/stdlib/stack.ml
new file mode 100644
index 000000000..8b1710cdd
--- /dev/null
+++ b/stdlib/stack.ml
@@ -0,0 +1,18 @@
+type 'a t = { mutable c : 'a list }
+
+exception Empty
+
+let new () = { c = [] }
+
+let clear s = s.c <- []
+
+let push x s = s.c <- x :: s.c
+
+let pop s =
+ match s.c with
+ hd::tl -> s.c <- tl; hd
+ | [] -> raise Empty
+
+let length s = List.length s.c
+
+let iter f s = List.iter f s.c