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 *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the GNU Library General Public License. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $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. *)
|
2000-04-13 05:16:02 -07:00
|
|
|
val top: 'a t -> 'a
|
|
|
|
(* [top s] returns the topmost element in stack [s],
|
|
|
|
or raises [Empty] if the stack is empty. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
val clear : 'a t -> unit
|
|
|
|
(* Discard all elements from a stack. *)
|
|
|
|
val length: 'a t -> int
|
|
|
|
(* Return the number of elements in a stack. *)
|
2000-04-02 18:57:52 -07:00
|
|
|
val iter: f:('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. *)
|