jon.recoil.org

Source file comparisons.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(** Interfaces for infix comparison operators and comparison functions. *)

open! Import

(** [Infix] lists the typical infix comparison operators. These functions are provided by
    [<M>.O] modules, i.e., modules that expose monomorphic infix comparisons over some
    [<M>.t]. *)
module type Infix = sig
  type t : any

  val ( >= ) : t -> t -> bool
  val ( <= ) : t -> t -> bool
  val ( = ) : t -> t -> bool
  val ( > ) : t -> t -> bool
  val ( < ) : t -> t -> bool
  val ( <> ) : t -> t -> bool
end

module type%template [@mode m = (global, local)] S = sig
  include Infix

  [%%template:
  [@@@mode.default m = (global, m)]

  val equal : t @ m -> t @ m -> bool

  (** [compare t1 t2] returns 0 if [t1] is equal to [t2], a negative integer if [t1] is
      less than [t2], and a positive integer if [t1] is greater than [t2]. *)
  val compare : t @ m -> t @ m -> int]

  val min : t -> t -> t
  val max : t -> t -> t
end

module type Infix_with_local_opt = sig
  type t

  external ( < ) : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%lessthan"
  external ( <= ) : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%lessequal"
  external ( <> ) : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%notequal"
  external ( = ) : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%equal"
  external ( > ) : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%greaterthan"
  external ( >= ) : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%greaterequal"
end

module type%template [@mode m = (global, local)] S_with_local_opt = sig
  include Infix_with_local_opt

  [%%template:
  [@@@mode.default m = (global, m)]

  external equal : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%equal"
  external compare : (t[@local_opt]) -> (t[@local_opt]) -> int = "%compare"]

  [%%template:
  [@@@mode.default m = (global, local)]

  val min : t @ m -> t @ m -> t @ m
  val max : t @ m -> t @ m -> t @ m]
end

module type Infix_with_zero_alloc = sig
  type t : any

  val ( >= ) : t -> t -> bool [@@zero_alloc]
  val ( <= ) : t -> t -> bool [@@zero_alloc]
  val ( = ) : t -> t -> bool [@@zero_alloc]
  val ( > ) : t -> t -> bool [@@zero_alloc]
  val ( < ) : t -> t -> bool [@@zero_alloc]
  val ( <> ) : t -> t -> bool [@@zero_alloc]
end

module type%template [@mode m = (global, local)] S_with_zero_alloc = sig
  include Infix_with_zero_alloc

  [%%template:
  [@@@mode.default m = (global, m)]

  val equal : t @ m -> t @ m -> bool [@@zero_alloc]

  (** [compare t1 t2] returns 0 if [t1] is equal to [t2], a negative integer if [t1] is
      less than [t2], and a positive integer if [t1] is greater than [t2]. *)
  val compare : t @ m -> t @ m -> int
  [@@zero_alloc]]

  val min : t -> t -> t [@@zero_alloc]
  val max : t -> t -> t [@@zero_alloc]
end

module type Infix_with_zero_alloc_strict = sig
  type t

  val ( >= ) : t -> t -> bool [@@zero_alloc strict]
  val ( <= ) : t -> t -> bool [@@zero_alloc strict]
  val ( = ) : t -> t -> bool [@@zero_alloc strict]
  val ( > ) : t -> t -> bool [@@zero_alloc strict]
  val ( < ) : t -> t -> bool [@@zero_alloc strict]
  val ( <> ) : t -> t -> bool [@@zero_alloc strict]
end

module type%template [@mode m = (global, local)] S_with_zero_alloc_strict = sig
  include Infix_with_zero_alloc_strict

  [%%template:
  [@@@mode.default m = (global, m)]

  val equal : t @ m -> t @ m -> bool [@@zero_alloc strict]

  (** [compare t1 t2] returns 0 if [t1] is equal to [t2], a negative integer if [t1] is
      less than [t2], and a positive integer if [t1] is greater than [t2]. *)
  val compare : t @ m -> t @ m -> int
  [@@zero_alloc strict]]

  val min : t -> t -> t [@@zero_alloc strict]
  val max : t -> t -> t [@@zero_alloc strict]
end