1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-09-04 05:07:15 -07:00
|
|
|
(* Module [Stack]: last-in first-out stacks *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-10-17 03:01:45 -07:00
|
|
|
(* This module implements stacks (LIFOs), with in-place modification. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
type 'a t
|
|
|
|
(* The type of stacks containing elements of type ['a]. *)
|
|
|
|
|
|
|
|
exception Empty
|
|
|
|
(* Raised when [pop] is applied to an empty stack. *)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
val create: unit -> 'a t
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Return a new stack, initially empty. *)
|
|
|
|
val push: 'a -> 'a t -> unit
|
|
|
|
(* [push x s] adds the element [x] at the top of stack [s]. *)
|
|
|
|
val pop: 'a t -> 'a
|
|
|
|
(* [pop s] removes and returns the topmost element in stack [s],
|
|
|
|
or raises [Empty] if the stack is empty. *)
|
|
|
|
val clear : 'a t -> unit
|
|
|
|
(* Discard all elements from a stack. *)
|
|
|
|
val length: 'a t -> int
|
|
|
|
(* Return the number of elements in a stack. *)
|
1997-10-31 04:59:29 -08:00
|
|
|
val iter: ('a -> unit) -> 'a t -> unit
|
1995-09-04 05:07:15 -07:00
|
|
|
(* [iter f s] applies [f] in turn to all elements of [s],
|
1995-08-09 06:15:01 -07:00
|
|
|
from the element at the top of the stack to the element at the
|
1995-05-04 03:15:53 -07:00
|
|
|
bottom of the stack. The stack itself is unchanged. *)
|