353 lines
3.8 KiB
HTML
353 lines
3.8 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Stdlib.Stack</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Stdlib.Stack</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Stdlib.Stack - no description
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Stdlib.Stack
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Stack</B>
|
|
|
|
<BR> :
|
|
<B>(module Stdlib__stack)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>type </I>
|
|
|
|
<B>'a</B>
|
|
|
|
<I>t </I>
|
|
|
|
<P>
|
|
<P>
|
|
The type of stacks containing elements of type
|
|
<B>'a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Empty </I>
|
|
|
|
<P>
|
|
<P>
|
|
Raised when
|
|
<B>Stack.pop</B>
|
|
|
|
or
|
|
<B>Stack.top</B>
|
|
|
|
is applied to an empty stack.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val create </I>
|
|
|
|
:
|
|
<B>unit -> 'a t</B>
|
|
|
|
<P>
|
|
Return a new stack, initially empty.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val push </I>
|
|
|
|
:
|
|
<B>'a -> 'a t -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>push x s</B>
|
|
|
|
adds the element
|
|
<B>x</B>
|
|
|
|
at the top of stack
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val pop </I>
|
|
|
|
:
|
|
<B>'a t -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>pop s</B>
|
|
|
|
removes and returns the topmost element in stack
|
|
<B>s</B>
|
|
|
|
,
|
|
or raises
|
|
<B>Stack.Empty</B>
|
|
|
|
if the stack is empty.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val pop_opt </I>
|
|
|
|
:
|
|
<B>'a t -> 'a option</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>pop_opt s</B>
|
|
|
|
removes and returns the topmost element in stack
|
|
<B>s</B>
|
|
|
|
,
|
|
or returns
|
|
<B>None</B>
|
|
|
|
if the stack is empty.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val top </I>
|
|
|
|
:
|
|
<B>'a t -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>top s</B>
|
|
|
|
returns the topmost element in stack
|
|
<B>s</B>
|
|
|
|
,
|
|
or raises
|
|
<B>Stack.Empty</B>
|
|
|
|
if the stack is empty.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val top_opt </I>
|
|
|
|
:
|
|
<B>'a t -> 'a option</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>top_opt s</B>
|
|
|
|
returns the topmost element in stack
|
|
<B>s</B>
|
|
|
|
,
|
|
or
|
|
<B>None</B>
|
|
|
|
if the stack is empty.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val clear </I>
|
|
|
|
:
|
|
<B>'a t -> unit</B>
|
|
|
|
<P>
|
|
Discard all elements from a stack.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val copy </I>
|
|
|
|
:
|
|
<B>'a t -> 'a t</B>
|
|
|
|
<P>
|
|
Return a copy of the given stack.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val is_empty </I>
|
|
|
|
:
|
|
<B>'a t -> bool</B>
|
|
|
|
<P>
|
|
Return
|
|
<B>true</B>
|
|
|
|
if the given stack is empty,
|
|
<B>false</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val length </I>
|
|
|
|
:
|
|
<B>'a t -> int</B>
|
|
|
|
<P>
|
|
Return the number of elements in a stack. Time complexity <A HREF="/cgi-bin/man/man2html?1+O">O</A>(1)
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val iter </I>
|
|
|
|
:
|
|
<B>('a -> unit) -> 'a t -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>iter f s</B>
|
|
|
|
applies
|
|
<B>f</B>
|
|
|
|
in turn to all elements of
|
|
<B>s</B>
|
|
|
|
,
|
|
from the element at the top of the stack to the element at the
|
|
bottom of the stack. The stack itself is unchanged.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fold </I>
|
|
|
|
:
|
|
<B>('b -> 'a -> 'b) -> 'b -> 'a t -> 'b</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>fold f accu s</B>
|
|
|
|
is
|
|
<B>(f (... (f (f accu x1) x2) ...) xn)</B>
|
|
|
|
where
|
|
<B>x1</B>
|
|
|
|
is the top of the stack,
|
|
<B>x2</B>
|
|
|
|
the second element,
|
|
and
|
|
<B>xn</B>
|
|
|
|
the bottom element. The stack is unchanged.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Iterators</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val to_seq </I>
|
|
|
|
:
|
|
<B>'a t -> 'a Seq.t</B>
|
|
|
|
<P>
|
|
Iterate on the stack, top to bottom.
|
|
It is safe to modify the stack during iteration.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.07
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val add_seq </I>
|
|
|
|
:
|
|
<B>'a t -> 'a Seq.t -> unit</B>
|
|
|
|
<P>
|
|
Add the elements from the iterator on the top of the stack.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.07
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val of_seq </I>
|
|
|
|
:
|
|
<B>'a Seq.t -> 'a t</B>
|
|
|
|
<P>
|
|
Create a stack from the iterator
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.07
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAE">Iterators</A><DD>
|
|
</DL>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:57 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|