ocaml/stdlib/stack.ml

32 lines
1.0 KiB
OCaml

(***********************************************************************)
(* *)
(* Caml Special Light *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1995 Institut National de Recherche en Informatique et *)
(* Automatique. Distributed only by permission. *)
(* *)
(***********************************************************************)
(* $Id$ *)
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