diff options
Diffstat (limited to 'ocaml-binary-annot/stdlib/stack.ml')
| -rw-r--r-- | ocaml-binary-annot/stdlib/stack.ml | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ocaml-binary-annot/stdlib/stack.ml b/ocaml-binary-annot/stdlib/stack.ml new file mode 100644 index 0000000000..03277d0794 --- /dev/null +++ b/ocaml-binary-annot/stdlib/stack.ml @@ -0,0 +1,42 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id$ *) + +type 'a t = { mutable c : 'a list } + +exception Empty + +let create () = { c = [] } + +let clear s = s.c <- [] + +let copy s = { c = 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 top s = + match s.c with + hd::_ -> hd + | [] -> raise Empty + +let is_empty s = (s.c = []) + +let length s = List.length s.c + +let iter f s = List.iter f s.c |
