1Set(3) OCaml library Set(3)
2
3
4
6 Set - Sets over ordered types.
7
9 Module Set
10
12 Module Set
13 : sig end
14
15
16 Sets over ordered types.
17
18 This module implements the set data structure, given a total ordering
19 function over the set elements. All operations over sets are purely
20 applicative (no side-effects). The implementation uses balanced binary
21 trees, and is therefore reasonably efficient: insertion and membership
22 take time logarithmic in the size of the set, for instance.
23
24 The Set.Make functor constructs implementations for any type, given a
25 compare function. For instance:
26 module IntPairs =
27 struct
28 type t = int * int
29 let compare (x0,y0) (x1,y1) =
30 match Stdlib.compare x0 x1 with
31 0 -> Stdlib.compare y0 y1
32 | c -> c
33 end
34
35 module PairsSet = Set.Make(IntPairs)
36
37 let m = PairsSet.(empty |> add (2,3) |> add (5,7) |> add (11,13))
38
39
40 This creates a new module PairsSet , with a new type PairsSet.t of sets
41 of int * int .
42
43
44
45
46
47 module type OrderedType = sig end
48
49
50 Input signature of the functor Set.Make .
51
52
53 module type S = sig end
54
55
56 Output signature of the functor Set.Make .
57
58
59 module Make : functor (Ord : OrderedType) -> sig end
60
61
62 Functor building an implementation of the set structure given a totally
63 ordered type.
64
65
66
67
68
69OCamldoc 2020-09-01 Set(3)