package bastet

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file Interface.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
(** {e Note}:
    Any data structure implementing one of these interfaces must also satisfy the corresponding laws in
    the corresponding {!Verify} module. *)

module type TYPE = sig
  type t
end

module type MAGMA = sig
  type t

  val append : t -> t -> t
end

module type MEDIAL_MAGMA = sig
  include MAGMA
end

module type MAGMA_ANY = sig
  type 'a t

  val append : 'a t -> 'a t -> 'a t
end

module type SEMIGROUP = sig
  include MAGMA
end

module type SEMIGROUP_ANY = sig
  include MAGMA_ANY
end

module type MONOID = sig
  (** A {!MONOID} only needs to be commutative with the {!empty} element. *)

  include SEMIGROUP

  val empty : t
end

module type MONOID_ANY = sig
  include SEMIGROUP_ANY

  val empty : 'a t
end

module type QUASIGROUP = sig
  include MAGMA
end

module type MEDIAL_QUASIGROUP = sig
  (** Every {!MEDIAL_QUASIGROUP} is isotopic to an {!ABELIAN_GROUP}. *)

  include MEDIAL_MAGMA
end

module type QUASIGROUP_ANY = sig
  include MAGMA_ANY
end

module type LOOP = sig
  (** A {!LOOP} only needs to be commutative with the {!empty} element. *)

  include QUASIGROUP

  val empty : t
end

module type LOOP_ANY = sig
  (** A {!LOOP_ANY} only needs to be commutative with the {!empty} element. *)

  include QUASIGROUP_ANY

  val empty : 'a t
end

module type GROUP = sig
  (** Include {i only} either {!LOOP} or {!MONOID}. *)

  include LOOP

  include MONOID with type t := t

  val inverse : t -> t
end

module type GROUP_ANY = sig
  (** Include {i only} either {!LOOP_ANY} or {!MONOID_ANY}. *)

  include LOOP_ANY

  include MONOID_ANY with type 'a t := 'a t

  val inverse : 'a t -> 'a t
end

(** Every {!GROUP} is a {!LOOP}. *)
module type GROUP_LOOP = functor (G : GROUP) -> LOOP

module type GROUP_LOOP_ANY = functor (G : GROUP_ANY) -> LOOP_ANY

module type ABELIAN_GROUP = sig
  include GROUP
end

module type ABELIAN_GROUP_ANY = sig
  include GROUP_ANY
end

module type FUNCTOR = sig
  type 'a t

  val map : ('a -> 'b) -> 'a t -> 'b t
end

module type APPLY = sig
  include FUNCTOR

  val apply : ('a -> 'b) t -> 'a t -> 'b t
end

module type APPLICATIVE = sig
  include APPLY

  val pure : 'a -> 'a t
end

module type MONAD = sig
  include APPLICATIVE

  val flat_map : 'a t -> ('a -> 'b t) -> 'b t
end

module type ALT = sig
  include FUNCTOR

  val alt : 'a t -> 'a t -> 'a t
end

module type PLUS = sig
  include ALT

  val empty : 'a t
end

module type ALTERNATIVE = sig
  include APPLICATIVE

  include PLUS with type 'a t := 'a t
end

module type FOLDABLE = sig
  type 'a t

  val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

  val fold_right : ('b -> 'a -> 'a) -> 'a -> 'b t -> 'a

  module Fold_Map : functor (M : MONOID) -> sig
    val fold_map : ('a -> M.t) -> 'a t -> M.t
  end

  module Fold_Map_Any : functor (M : MONOID_ANY) -> sig
    val fold_map : ('a -> 'b M.t) -> 'a t -> 'b M.t
  end

  module Fold_Map_Plus : functor (P : PLUS) -> sig
    val fold_map : ('a -> 'b P.t) -> 'a t -> 'b P.t
  end
end

module type UNFOLDABLE = sig
  type 'a t

  val unfold : ('a -> ('a * 'a) option) -> 'a -> 'a t
end

module type TRAVERSABLE = sig
  include FUNCTOR

  include FOLDABLE with type 'a t := 'a t

  type 'a applicative_t

  val traverse : ('a -> 'b applicative_t) -> 'a t -> 'b t applicative_t

  val sequence : 'a applicative_t t -> 'a t applicative_t
end

module type TRAVERSABLE_F = functor (A : APPLICATIVE) ->
  TRAVERSABLE with type 'a applicative_t = 'a A.t

module type SEMIGROUPOID = sig
  type ('a, 'b) t

  val compose : ('b, 'c) t -> ('a, 'b) t -> ('a, 'c) t
end

module type CATEGORY = sig
  include SEMIGROUPOID

  val id : ('a, 'a) t
end

module type EQ = sig
  type t

  val eq : t -> t -> bool
end

module type QUASIREFLEXIVE_EQ = sig
  include EQ
end

module type EQ1 = sig
  type 'a t

  val eq : 'a t -> 'a t -> bool
end

module type EQ2 = sig
  type ('a, 'b) t

  val eq : ('a, 'b) t -> ('a, 'b) t -> bool
end

type ordering =
  [ `less_than
  | `equal_to
  | `greater_than ]

let invert ordering =
  match ordering with
  | `less_than -> `greater_than
  | `greater_than -> `less_than
  | `equal_to -> `equal_to

let int_to_ordering x =
  match x < 0 with
  | true -> `less_than
  | false -> (
      match x = 0 with
      | true -> `equal_to
      | false -> `greater_than)

let unsafe_compare a b =
  match a < b with
  | true -> `less_than
  | false -> (
      match a = b with
      | true -> `equal_to
      | false -> `greater_than)

module type ORD = sig
  include EQ

  val compare : t -> t -> ordering
end

module Ordering (O : ORD) = struct
  let less_than = (fun a b -> O.compare a b = `less_than : O.t -> O.t -> bool)

  and greater_than = (fun a b -> O.compare a b = `greater_than : O.t -> O.t -> bool)

  and less_than_or_equal = (fun a b -> O.compare a b <> `greater_than : O.t -> O.t -> bool)

  and greater_than_or_equal = (fun a b -> O.compare a b <> `less_than : O.t -> O.t -> bool)
end

module type BOUNDED = sig
  include ORD

  val top : t

  val bottom : t
end

module type JOIN_SEMILATTICE = sig
  type t

  val join : t -> t -> t
end

module type MEET_SEMILATTICE = sig
  type t

  val meet : t -> t -> t
end

module type BOUNDED_JOIN_SEMILATTICE = sig
  include JOIN_SEMILATTICE

  val bottom : t
end

module type BOUNDED_MEET_SEMILATTICE = sig
  include MEET_SEMILATTICE

  val top : t
end

module type LATTICE = sig
  include JOIN_SEMILATTICE

  include MEET_SEMILATTICE with type t := t
end

module type BOUNDED_LATTICE = sig
  include BOUNDED_JOIN_SEMILATTICE

  include BOUNDED_MEET_SEMILATTICE with type t := t
end

module type DISTRIBUTIVE_LATTICE = sig
  include LATTICE
end

module type BOUNDED_DISTRIBUTIVE_LATTICE = sig
  include BOUNDED_LATTICE
end

module type HEYTING_ALGEBRA = sig
  include ORD

  include BOUNDED_DISTRIBUTIVE_LATTICE with type t := t

  val not : t -> t

  val implies : t -> t -> t
end

module type INVOLUTIVE_HEYTING_ALGEBRA = sig
  include HEYTING_ALGEBRA
end

module type BOOLEAN_ALGEBRA = sig
  include HEYTING_ALGEBRA
end

module type SHOW = sig
  type t

  val show : t -> string
end

module type SEMIRING = sig
  type t

  val add : t -> t -> t

  val zero : t

  val multiply : t -> t -> t

  val one : t
end

module type RING = sig
  include SEMIRING

  val subtract : t -> t -> t
end

module type COMMUTATIVE_RING = sig
  include RING
end

module type DIVISION_RING = sig
  include RING

  val reciprocal : t -> t
end

module type EUCLIDEAN_RING = sig
  include COMMUTATIVE_RING

  val degree : t -> int

  val divide : t -> t -> t

  val modulo : t -> t -> t
end

module type FIELD = sig
  include EUCLIDEAN_RING

  include DIVISION_RING with type t := t
end

module type INVARIANT = sig
  type 'a t

  val imap : ('a -> 'b) -> ('b -> 'a) -> 'a t -> 'b t
end

module type CONTRAVARIANT = sig
  type 'a t

  val cmap : ('b -> 'a) -> 'a t -> 'b t
end

module type PROFUNCTOR = sig
  type ('a, 'b) t

  val dimap : ('a -> 'b) -> ('c -> 'd) -> ('b, 'c) t -> ('a, 'd) t
end

module type MONAD_ZERO = sig
  include MONAD

  include ALTERNATIVE with type 'a t := 'a t
end

module type MONAD_PLUS = sig
  include MONAD_ZERO
end

module type EXTEND = sig
  include FUNCTOR

  val extend : ('a t -> 'b) -> 'a t -> 'b t
end

module type COMONAD = sig
  include EXTEND

  val extract : 'a t -> 'a
end

module type BIFUNCTOR = sig
  type ('a, 'b) t

  val bimap : ('a -> 'b) -> ('c -> 'd) -> ('a, 'c) t -> ('b, 'd) t
end

module type BIAPPLY = sig
  include BIFUNCTOR

  val biapply : ('a -> 'b, 'c -> 'd) t -> ('a, 'c) t -> ('b, 'd) t
end

module type BIAPPLICATIVE = sig
  include BIAPPLY

  val bipure : 'a -> 'b -> ('a, 'b) t
end

module type BIFOLDABLE = sig
  type ('a, 'b) t

  val bifold_left : ('c -> 'a -> 'c) -> ('c -> 'b -> 'c) -> 'c -> ('a, 'b) t -> 'c

  val bifold_right : ('a -> 'c -> 'c) -> ('b -> 'c -> 'c) -> 'c -> ('a, 'b) t -> 'c

  module Fold_Map : functor (M : MONOID) -> sig
    val fold_map : ('a -> M.t) -> ('b -> M.t) -> ('a, 'b) t -> M.t
  end

  module Fold_Map_Any : functor (M : MONOID_ANY) -> sig
    val fold_map : ('a -> 'a M.t) -> ('b -> 'a M.t) -> ('a, 'b) t -> 'a M.t
  end

  module Fold_Map_Plus : functor (P : PLUS) -> sig
    val fold_map : ('a -> 'a P.t) -> ('b -> 'a P.t) -> ('a, 'b) t -> 'a P.t
  end
end

module type BITRAVERSABLE = sig
  include BIFUNCTOR

  include BIFOLDABLE with type ('a, 'b) t := ('a, 'b) t

  type 'a applicative_t

  val bitraverse :
    ('a -> 'c applicative_t) -> ('b -> 'd applicative_t) -> ('a, 'b) t -> ('c, 'd) t applicative_t

  val bisequence : ('a applicative_t, 'b applicative_t) t -> ('a, 'b) t applicative_t
end

module type BITRAVERSABLE_F = functor (A : APPLICATIVE) ->
  BITRAVERSABLE with type 'a applicative_t = 'a A.t

module type BICONTRAVARIANT = sig
  type ('a, 'b) t

  val bicmap : ('b -> 'a) -> ('d -> 'c) -> ('a, 'c) t -> ('b, 'd) t
end