1Set.S(3)                         OCaml library                        Set.S(3)
2
3
4

NAME

6       Set.S - Output signature of the functor Set.Make.
7

Module type

9       Module type   Set.S
10

Documentation

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 disjoint : t -> t -> bool
100
101       Test if two sets are disjoint.
102
103
104       Since 4.08.0
105
106
107
108       val diff : t -> t -> t
109
110       Set  difference: diff s1 s2 contains the elements of s1 that are not in
111       s2 .
112
113
114
115       val compare : t -> t -> int
116
117       Total ordering between sets. Can be used as the ordering  function  for
118       doing sets of sets.
119
120
121
122       val equal : t -> t -> bool
123
124
125       equal  s1  s2 tests whether the sets s1 and s2 are equal, that is, con‐
126       tain equal elements.
127
128
129
130       val subset : t -> t -> bool
131
132
133       subset s1 s2 tests whether the set s1 is a subset of the set s2 .
134
135
136
137       val iter : (elt -> unit) -> t -> unit
138
139
140       iter f s applies f in turn to all elements of s .  The  elements  of  s
141       are  presented  to  f  in increasing order with respect to the ordering
142       over the type of the elements.
143
144
145
146       val map : (elt -> elt) -> t -> t
147
148
149       map f s is the set whose elements are f a0 , f a1 ...  f
150               aN , where a0 , a1 ...  aN are the elements of s .
151
152       The elements are passed to f in increasing order with  respect  to  the
153       ordering over the type of the elements.
154
155       If  no element of s is changed by f , s is returned unchanged. (If each
156       output of f is physically equal to its input, the returned set is phys‐
157       ically equal to s .)
158
159
160       Since 4.04.0
161
162
163
164       val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
165
166
167       fold f s init computes (f xN ... (f x2 (f x1 init))...)  , where x1 ...
168       xN are the elements of s , in increasing order.
169
170
171
172       val for_all : (elt -> bool) -> t -> bool
173
174
175       for_all f s checks if all elements of the set satisfy the predicate f .
176
177
178
179       val exists : (elt -> bool) -> t -> bool
180
181
182       exists f s checks if at least one element  of  the  set  satisfies  the
183       predicate f .
184
185
186
187       val filter : (elt -> bool) -> t -> t
188
189
190       filter  f s returns the set of all elements in s that satisfy predicate
191       f . If f satisfies every element in s , s is  returned  unchanged  (the
192       result of the function is then physically equal to s ).
193
194
195       Before4.03 Physical equality was not ensured.
196
197
198
199
200       val filter_map : (elt -> elt option) -> t -> t
201
202
203       filter_map f s returns the set of all v such that f x = Some v for some
204       element x of s .
205
206       For example,
207       filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s
208       is the set of halves of the even elements of s .
209
210       If no element of s is changed or dropped by f (if f x = Some x for each
211       element  x  ), then s is returned unchanged: the result of the function
212       is then physically equal to s .
213
214
215       Since 4.11.0
216
217
218
219       val partition : (elt -> bool) -> t -> t * t
220
221
222       partition f s returns a pair of sets (s1, s2) , where s1 is the set  of
223       all  the elements of s that satisfy the predicate f , and s2 is the set
224       of all the elements of s that do not satisfy f .
225
226
227
228       val cardinal : t -> int
229
230       Return the number of elements of a set.
231
232
233
234       val elements : t -> elt list
235
236       Return the list of all elements of the given set.  The returned list is
237       sorted  in  increasing order with respect to the ordering Ord.compare ,
238       where Ord is the argument given to Set.Make .
239
240
241
242       val min_elt : t -> elt
243
244       Return the smallest element of the  given  set  (with  respect  to  the
245       Ord.compare ordering), or raise Not_found if the set is empty.
246
247
248
249       val min_elt_opt : t -> elt option
250
251       Return  the  smallest  element  of  the  given set (with respect to the
252       Ord.compare ordering), or None if the set is empty.
253
254
255       Since 4.05
256
257
258
259       val max_elt : t -> elt
260
261       Same as Set.S.min_elt , but returns the largest element  of  the  given
262       set.
263
264
265
266       val max_elt_opt : t -> elt option
267
268       Same  as  Set.S.min_elt_opt  ,  but  returns the largest element of the
269       given set.
270
271
272       Since 4.05
273
274
275
276       val choose : t -> elt
277
278       Return one element of the given set, or raise Not_found if the  set  is
279       empty.  Which element is chosen is unspecified, but equal elements will
280       be chosen for equal sets.
281
282
283
284       val choose_opt : t -> elt option
285
286       Return one element of the given set, or None if the set is empty. Which
287       element is chosen is unspecified, but equal elements will be chosen for
288       equal sets.
289
290
291       Since 4.05
292
293
294
295       val split : elt -> t -> t * bool * t
296
297
298       split x s returns a triple (l, present, r) , where l is the set of ele‐
299       ments  of s that are strictly less than x ; r is the set of elements of
300       s that are strictly greater than x ; present is false if s contains  no
301       element equal to x , or true if s contains an element equal to x .
302
303
304
305       val find : elt -> t -> elt
306
307
308       find  x s returns the element of s equal to x (according to Ord.compare
309       ), or raise Not_found if no such element exists.
310
311
312       Since 4.01.0
313
314
315
316       val find_opt : elt -> t -> elt option
317
318
319       find_opt x s returns the element of s equal to x (according to Ord.com‐
320       pare ), or None if no such element exists.
321
322
323       Since 4.05
324
325
326
327       val find_first : (elt -> bool) -> t -> elt
328
329
330       find_first  f  s  , where f is a monotonically increasing function, re‐
331       turns the lowest element e of s such that f e , or raises Not_found  if
332       no such element exists.
333
334       For  example,  find_first (fun e -> Ord.compare e x >= 0) s will return
335       the first element e of s where Ord.compare e x >= 0 (intuitively: e  >=
336       x ), or raise Not_found if x is greater than any element of s .
337
338
339       Since 4.05
340
341
342
343       val find_first_opt : (elt -> bool) -> t -> elt option
344
345
346       find_first_opt  f  s  , where f is a monotonically increasing function,
347       returns an option containing the lowest element e of s such that f e  ,
348       or None if no such element exists.
349
350
351       Since 4.05
352
353
354
355       val find_last : (elt -> bool) -> t -> elt
356
357
358       find_last f s , where f is a monotonically decreasing function, returns
359       the highest element e of s such that f e , or raises  Not_found  if  no
360       such element exists.
361
362
363       Since 4.05
364
365
366
367       val find_last_opt : (elt -> bool) -> t -> elt option
368
369
370       find_last_opt f s , where f is a monotonically decreasing function, re‐
371       turns an option containing the highest element e of s such that f  e  ,
372       or None if no such element exists.
373
374
375       Since 4.05
376
377
378
379       val of_list : elt list -> t
380
381
382       of_list  l creates a set from a list of elements.  This is usually more
383       efficient than folding add over the list, except perhaps for lists with
384       many duplicated elements.
385
386
387       Since 4.02.0
388
389
390
391
392   Iterators
393       val to_seq_from : elt -> t -> elt Seq.t
394
395
396       to_seq_from  x s iterates on a subset of the elements of s in ascending
397       order, from x or above.
398
399
400       Since 4.07
401
402
403
404       val to_seq : t -> elt Seq.t
405
406       Iterate on the whole set, in ascending order
407
408
409       Since 4.07
410
411
412
413       val to_rev_seq : t -> elt Seq.t
414
415       Iterate on the whole set, in descending order
416
417
418       Since 4.12
419
420
421
422       val add_seq : elt Seq.t -> t -> t
423
424       Add the given elements to the set, in order.
425
426
427       Since 4.07
428
429
430
431       val of_seq : elt Seq.t -> t
432
433       Build a set from the given bindings
434
435
436       Since 4.07
437
438
439
440
441
442OCamldoc                          2022-02-04                          Set.S(3)
Impressum