1Stack(3)                         OCaml library                        Stack(3)
2
3
4

NAME

6       Stack - Last-in first-out stacks.
7

Module

9       Module   Stack
10

Documentation

12       Module Stack
13        : sig end
14
15
16       Last-in first-out stacks.
17
18       This module implements stacks (LIFOs), with in-place modification.
19
20
21
22
23
24       type 'a t
25
26
27       The type of stacks containing elements of type 'a .
28
29
30
31       exception Empty
32
33
34       Raised when Stack.pop or Stack.top is applied to an empty stack.
35
36
37
38       val create : unit -> 'a t
39
40       Return a new stack, initially empty.
41
42
43
44       val push : 'a -> 'a t -> unit
45
46
47       push x s adds the element x at the top of stack s .
48
49
50
51       val pop : 'a t -> 'a
52
53
54       pop  s  removes  and returns the topmost element in stack s , or raises
55       Stack.Empty if the stack is empty.
56
57
58
59       val top : 'a t -> 'a
60
61
62       top s returns the topmost element in stack s , or raises Stack.Empty if
63       the stack is empty.
64
65
66
67       val clear : 'a t -> unit
68
69       Discard all elements from a stack.
70
71
72
73       val copy : 'a t -> 'a t
74
75       Return a copy of the given stack.
76
77
78
79       val is_empty : 'a t -> bool
80
81       Return true if the given stack is empty, false otherwise.
82
83
84
85       val length : 'a t -> int
86
87       Return the number of elements in a stack. Time complexity O(1)
88
89
90
91       val iter : ('a -> unit) -> 'a t -> unit
92
93
94       iter  f  s applies f in turn to all elements of s , from the element at
95       the top of the stack to the element at the bottom  of  the  stack.  The
96       stack itself is unchanged.
97
98
99
100       val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
101
102
103       fold  f  accu  s is (f (... (f (f accu x1) x2) ...) xn) where x1 is the
104       top of the stack, x2 the second element, and xn the bottom element. The
105       stack is unchanged.
106
107
108       Since 4.03
109
110
111
112
113       === Iterators ===
114
115
116       val to_seq : 'a t -> 'a Seq.t
117
118       Iterate  on  the  stack, top to bottom.  It is safe to modify the stack
119       during iteration.
120
121
122       Since 4.07
123
124
125
126       val add_seq : 'a t -> 'a Seq.t -> unit
127
128       Add the elements from the iterator on the top of the stack.
129
130
131       Since 4.07
132
133
134
135       val of_seq : 'a Seq.t -> 'a t
136
137       Create a stack from the iterator
138
139
140       Since 4.07
141
142
143
144
145
146OCamldoc                          2019-02-02                          Stack(3)
Impressum