1Set.S(3) OCamldoc Set.S(3)
2
3
4
6 Set.S - Output signature of the functor Set.Make.
7
9 Module type Set.S
10
12 Module type S
13 = sig end
14
15
16 Output signature of the functor Set.Make .
17
18
19
20
21
22 type elt
23
24
25 The type of the set elements.
26
27
28 type t
29
30
31 The type of sets.
32
33
34
35 val empty : t
36
37 The empty set.
38
39
40
41 val is_empty : t -> bool
42
43 Test whether a set is empty or not.
44
45
46
47 val mem : elt -> t -> bool
48
49
50 mem x s tests whether x belongs to the set s .
51
52
53
54 val add : elt -> t -> t
55
56
57 add x s returns a set containing all elements of s , plus x . If x was
58 already in s , s is returned unchanged (the result of the function is
59 then physically equal to s ).
60
61
62 Before4.03 Physical equality was not ensured.
63
64
65
66
67 val singleton : elt -> t
68
69
70 singleton x returns the one-element set containing only x .
71
72
73
74 val remove : elt -> t -> t
75
76
77 remove x s returns a set containing all elements of s , except x . If x
78 was not in s , s is returned unchanged (the result of the function is
79 then physically equal to s ).
80
81
82 Before4.03 Physical equality was not ensured.
83
84
85
86
87 val union : t -> t -> t
88
89 Set union.
90
91
92
93 val inter : t -> t -> t
94
95 Set intersection.
96
97
98
99 val diff : t -> t -> t
100
101 Set difference.
102
103
104
105 val compare : t -> t -> int
106
107 Total ordering between sets. Can be used as the ordering function for
108 doing sets of sets.
109
110
111
112 val equal : t -> t -> bool
113
114
115 equal s1 s2 tests whether the sets s1 and s2 are equal, that is, con‐
116 tain equal elements.
117
118
119
120 val subset : t -> t -> bool
121
122
123 subset s1 s2 tests whether the set s1 is a subset of the set s2 .
124
125
126
127 val iter : (elt -> unit) -> t -> unit
128
129
130 iter f s applies f in turn to all elements of s . The elements of s
131 are presented to f in increasing order with respect to the ordering
132 over the type of the elements.
133
134
135
136 val map : (elt -> elt) -> t -> t
137
138
139 map f s is the set whose elements are f a0 , f a1 ... f aN , where a0
140 , a1 ... aN are the elements of s .
141
142 The elements are passed to f in increasing order with respect to the
143 ordering over the type of the elements.
144
145 If no element of s is changed by f , s is returned unchanged. (If each
146 output of f is physically equal to its input, the returned set is phys‐
147 ically equal to s .)
148
149
150 Since 4.04.0
151
152
153
154 val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
155
156
157 fold f s a computes (f xN ... (f x2 (f x1 a))...) , where x1 ... xN
158 are the elements of s , in increasing order.
159
160
161
162 val for_all : (elt -> bool) -> t -> bool
163
164
165 for_all p s checks if all elements of the set satisfy the predicate p .
166
167
168
169 val exists : (elt -> bool) -> t -> bool
170
171
172 exists p s checks if at least one element of the set satisfies the
173 predicate p .
174
175
176
177 val filter : (elt -> bool) -> t -> t
178
179
180 filter p s returns the set of all elements in s that satisfy predicate
181 p . If p satisfies every element in s , s is returned unchanged (the
182 result of the function is then physically equal to s ).
183
184
185 Before4.03 Physical equality was not ensured.
186
187
188
189
190 val partition : (elt -> bool) -> t -> t * t
191
192
193 partition p s returns a pair of sets (s1, s2) , where s1 is the set of
194 all the elements of s that satisfy the predicate p , and s2 is the set
195 of all the elements of s that do not satisfy p .
196
197
198
199 val cardinal : t -> int
200
201 Return the number of elements of a set.
202
203
204
205 val elements : t -> elt list
206
207 Return the list of all elements of the given set. The returned list is
208 sorted in increasing order with respect to the ordering Ord.compare ,
209 where Ord is the argument given to Set.Make .
210
211
212
213 val min_elt : t -> elt
214
215 Return the smallest element of the given set (with respect to the
216 Ord.compare ordering), or raise Not_found if the set is empty.
217
218
219
220 val min_elt_opt : t -> elt option
221
222 Return the smallest element of the given set (with respect to the
223 Ord.compare ordering), or None if the set is empty.
224
225
226 Since 4.05
227
228
229
230 val max_elt : t -> elt
231
232 Same as Set.S.min_elt , but returns the largest element of the given
233 set.
234
235
236
237 val max_elt_opt : t -> elt option
238
239 Same as Set.S.min_elt_opt , but returns the largest element of the
240 given set.
241
242
243 Since 4.05
244
245
246
247 val choose : t -> elt
248
249 Return one element of the given set, or raise Not_found if the set is
250 empty. Which element is chosen is unspecified, but equal elements will
251 be chosen for equal sets.
252
253
254
255 val choose_opt : t -> elt option
256
257 Return one element of the given set, or None if the set is empty. Which
258 element is chosen is unspecified, but equal elements will be chosen for
259 equal sets.
260
261
262 Since 4.05
263
264
265
266 val split : elt -> t -> t * bool * t
267
268
269 split x s returns a triple (l, present, r) , where l is the set of ele‐
270 ments of s that are strictly less than x ; r is the set of elements of
271 s that are strictly greater than x ; present is false if s contains no
272 element equal to x , or true if s contains an element equal to x .
273
274
275
276 val find : elt -> t -> elt
277
278
279 find x s returns the element of s equal to x (according to Ord.compare
280 ), or raise Not_found if no such element exists.
281
282
283 Since 4.01.0
284
285
286
287 val find_opt : elt -> t -> elt option
288
289
290 find_opt x s returns the element of s equal to x (according to Ord.com‐
291 pare ), or None if no such element exists.
292
293
294 Since 4.05
295
296
297
298 val find_first : (elt -> bool) -> t -> elt
299
300
301 find_first f s , where f is a monotonically increasing function,
302 returns the lowest element e of s such that f e , or raises Not_found
303 if no such element exists.
304
305 For example, find_first (fun e -> Ord.compare e x >= 0) s will return
306 the first element e of s where Ord.compare e x >= 0 (intuitively: e >=
307 x ), or raise Not_found if x is greater than any element of s .
308
309
310 Since 4.05
311
312
313
314 val find_first_opt : (elt -> bool) -> t -> elt option
315
316
317 find_first_opt f s , where f is a monotonically increasing function,
318 returns an option containing the lowest element e of s such that f e ,
319 or None if no such element exists.
320
321
322 Since 4.05
323
324
325
326 val find_last : (elt -> bool) -> t -> elt
327
328
329 find_last f s , where f is a monotonically decreasing function, returns
330 the highest element e of s such that f e , or raises Not_found if no
331 such element exists.
332
333
334 Since 4.05
335
336
337
338 val find_last_opt : (elt -> bool) -> t -> elt option
339
340
341 find_last_opt f s , where f is a monotonically decreasing function,
342 returns an option containing the highest element e of s such that f e ,
343 or None if no such element exists.
344
345
346 Since 4.05
347
348
349
350 val of_list : elt list -> t
351
352
353 of_list l creates a set from a list of elements. This is usually more
354 efficient than folding add over the list, except perhaps for lists with
355 many duplicated elements.
356
357
358 Since 4.02.0
359
360
361
362
363
3642018-04-14 source: Set.S(3)