Source file indexed_alternative.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
module type LAWS_MONOID = sig
type ('a, 'index) t
include Indexed_applicative.LAWS with type ('a, 'index) t := ('a, 'index) t
val alternative_monoid_1 : unit -> (('a, 'index) t, ('a, 'index) t) Law.t
val alternative_monoid_2 : unit -> (('a, 'index) t, ('a, 'index) t) Law.t
val alternative_monoid_3 :
unit
-> ( ('a, 'index) t
, ('a, 'index) t -> ('a, 'index) t -> ('a, 'index) t )
Law.t
end
module type LAWS_RIGHT_DISTRIBUTIVITY = sig
type ('a, 'index) t
include Indexed_applicative.LAWS with type ('a, 'index) t := ('a, 'index) t
val alternative_right_distrib_1 :
unit
-> ( ('a -> 'b, 'index) t
, ('a -> 'b, 'index) t -> ('a, 'index) t -> ('b, 'index) t )
Law.t
end
module type LAWS_RIGHT_ABSORPTION = sig
type ('a, 'index) t
include Indexed_applicative.LAWS with type ('a, 'index) t := ('a, 'index) t
val alternative_right_absorb_1 :
unit -> (('a, 'index) t, ('a, 'index) t) Law.t
end
module For_monoidal (A : Preface_specs.INDEXED_ALTERNATIVE) :
LAWS_MONOID with type ('a, 'index) t := ('a, 'index) A.t = struct
open Law
include Indexed_applicative.For (A)
let alternative_monoid_1 () =
let lhs = A.(combine neutral)
and rhs x = x in
law ("neutral <|> x" =~ lhs) ("x" =~ rhs)
;;
let alternative_monoid_2 () =
let lhs x = A.(combine x neutral)
and rhs x = x in
law ("x <|> neutral" =~ lhs) ("x" =~ rhs)
;;
let alternative_monoid_3 () =
let lhs a b c = A.(Infix.(a <|> b) <|> c)
and rhs a b c = A.(a <|> Infix.(b <|> c)) in
law ("(a <|> b) <|> c" =~ lhs) ("a <|> (b <|> c)" =~ rhs)
;;
end
module For_right_distributivity (A : Preface_specs.INDEXED_ALTERNATIVE) :
LAWS_RIGHT_DISTRIBUTIVITY with type ('a, 'index) t := ('a, 'index) A.t =
struct
open Law
include Indexed_applicative.For (A)
let alternative_right_distrib_1 () =
let lhs f g x = A.(Infix.(f <|> g) <*> x)
and rhs f g x = A.(Infix.(f <*> x) <|> Infix.(g <*> x)) in
law ("(f <|> g) <*> a" =~ lhs) ("(f <*> a) <|> (g <*> a)" =~ rhs)
;;
end
module For_right_absorbtion (A : Preface_specs.INDEXED_ALTERNATIVE) :
LAWS_RIGHT_ABSORPTION with type ('a, 'index) t := ('a, 'index) A.t = struct
open Law
include Indexed_applicative.For (A)
let alternative_right_absorb_1 () =
let lhs = A.(apply neutral)
and rhs _ = A.neutral in
law ("neutral <*> x" =~ lhs) ("neutral" =~ rhs)
;;
end