2
(*i $Id: predicate.mli 6621 2005-01-21 17:24:37Z herbelin $ i*)
4
(* Module [Pred]: sets over infinite ordered types with complement. *)
6
(* This module implements the set data structure, given a total ordering
7
function over the set elements. All operations over sets
8
are purely applicative (no side-effects).
9
The implementation uses the Set library. *)
11
module type OrderedType =
14
val compare: t -> t -> int
16
(* The input signature of the functor [Pred.Make].
17
[t] is the type of the set elements.
18
[compare] is a total ordering function over the set elements.
19
This is a two-argument function [f] such that
20
[f e1 e2] is zero if the elements [e1] and [e2] are equal,
21
[f e1 e2] is strictly negative if [e1] is smaller than [e2],
22
and [f e1 e2] is strictly positive if [e1] is greater than [e2].
23
Example: a suitable ordering function is
24
the generic structural comparison function [compare]. *)
29
(* The type of the set elements. *)
31
(* The type of sets. *)
36
val is_empty: t -> bool
37
(* Test whether a set is empty or not. *)
38
val is_full: t -> bool
39
(* Test whether a set contains the whole type or not. *)
40
val mem: elt -> t -> bool
41
(* [mem x s] tests whether [x] belongs to the set [s]. *)
42
val singleton: elt -> t
43
(* [singleton x] returns the one-element set containing only [x]. *)
44
val add: elt -> t -> t
45
(* [add x s] returns a set containing all elements of [s],
46
plus [x]. If [x] was already in [s], [s] is returned unchanged. *)
47
val remove: elt -> t -> t
48
(* [remove x s] returns a set containing all elements of [s],
49
except [x]. If [x] was not in [s], [s] is returned unchanged. *)
50
val union: t -> t -> t
51
val inter: t -> t -> t
53
val complement: t -> t
54
(* Union, intersection, difference and set complement. *)
55
val equal: t -> t -> bool
56
(* [equal s1 s2] tests whether the sets [s1] and [s2] are
57
equal, that is, contain equal elements. *)
58
val subset: t -> t -> bool
59
(* [subset s1 s2] tests whether the set [s1] is a subset of
61
val elements: t -> bool * elt list
62
(* Gives a finite representation of the predicate: if the
63
boolean is false, then the predicate is given in extension.
64
if it is true, then the complement is given *)
67
module Make(Ord: OrderedType): (S with type elt = Ord.t)
68
(* Functor building an implementation of the set structure
69
given a totally ordered type. *)