From e27406829f2f969ececd7efe7465bb490ec0c8db Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 13 Apr 2000 12:16:02 +0000 Subject: [PATCH] Ajout Stack.top git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3072 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- stdlib/stack.ml | 5 +++++ stdlib/stack.mli | 3 +++ 2 files changed, 8 insertions(+) diff --git a/stdlib/stack.ml b/stdlib/stack.ml index 0a422b308..bcc616f79 100644 --- a/stdlib/stack.ml +++ b/stdlib/stack.ml @@ -27,6 +27,11 @@ let pop s = hd::tl -> s.c <- tl; hd | [] -> raise Empty +let top s = + match s.c with + hd::_ -> hd + | [] -> raise Empty + let length s = List.length s.c let iter f s = List.iter f s.c diff --git a/stdlib/stack.mli b/stdlib/stack.mli index b90d56871..e46288a63 100644 --- a/stdlib/stack.mli +++ b/stdlib/stack.mli @@ -29,6 +29,9 @@ val push: 'a -> 'a t -> unit 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 top: 'a t -> 'a + (* [top s] 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