Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / stdlib / stack.ml
blob03277d0794d0f362b3739a3509dce90315018e22
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the GNU Library General Public License, with *)
10 (* the special exception on linking described in file ../LICENSE. *)
11 (* *)
12 (***********************************************************************)
14 (* $Id$ *)
16 type 'a t = { mutable c : 'a list }
18 exception Empty
20 let create () = { c = [] }
22 let clear s = s.c <- []
24 let copy s = { c = s.c }
26 let push x s = s.c <- x :: s.c
28 let pop s =
29 match s.c with
30 hd::tl -> s.c <- tl; hd
31 | [] -> raise Empty
33 let top s =
34 match s.c with
35 hd::_ -> hd
36 | [] -> raise Empty
38 let is_empty s = (s.c = [])
40 let length s = List.length s.c
42 let iter f s = List.iter f s.c