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
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
open QCheck2
module Suite_monoidal_aux
(R : Model.COVARIANT_2)
(F : Preface_specs.INDEXED_ALTERNATIVE
with type ('a, 'index) t = ('a, 'index) R.t)
(A : Model.T0)
(B : Model.T0)
(Index : Model.T0) =
struct
module Laws = Preface_laws.Indexed_alternative.For_monoidal (F)
let print pp = Format.asprintf "%a" (R.pp pp Index.pp)
let alternative_monoid_1 count =
let generator = R.generator A.generator Index.generator in
let print = print A.pp in
Util.test ~count ~print generator Laws.alternative_monoid_1
(fun lhs rhs x ->
let left = lhs x
and right = rhs x in
R.equal A.equal Index.equal left right )
;;
let alternative_monoid_2 count =
let generator = R.generator A.generator Index.generator in
let print = print A.pp in
Util.test ~count ~print generator Laws.alternative_monoid_2
(fun lhs rhs x ->
let left = lhs x
and right = rhs x in
R.equal A.equal Index.equal left right )
;;
let alternative_monoid_3 count =
let generator =
Gen.tup3
(R.generator A.generator Index.generator)
(R.generator A.generator Index.generator)
(R.generator A.generator Index.generator)
in
let print = Print.tup3 (print A.pp) (print A.pp) (print A.pp) in
Util.test ~count ~print generator Laws.alternative_monoid_3
(fun lhs rhs (x, y, z) ->
let left = lhs x y z
and right = rhs x y z in
R.equal A.equal Index.equal left right )
;;
let tests ~count =
[
alternative_monoid_1 count
; alternative_monoid_2 count
; alternative_monoid_3 count
]
;;
end
module Suite_right_distributivity_aux
(R : Model.COVARIANT_2)
(F : Preface_specs.INDEXED_ALTERNATIVE
with type ('a, 'index) t = ('a, 'index) R.t)
(A : Model.T0)
(B : Model.T0)
(Index : Model.T0) =
struct
module Laws = Preface_laws.Indexed_alternative.For_right_distributivity (F)
let print pp = Format.asprintf "%a" (R.pp pp Index.pp)
let alternative_right_distrib_1 count =
let generator =
let f = R.generator (fun1 A.observable B.generator) Index.generator in
Gen.tup3 f f (R.generator A.generator Index.generator)
in
let print (_, _, x) = print A.pp x in
Util.test ~count ~print generator Laws.alternative_right_distrib_1
(fun lhs rhs (ff, gg, x) ->
let f = F.(Fn.apply <$> ff)
and g = F.(Fn.apply <$> gg) in
let left = lhs f g x
and right = rhs f g x in
R.equal B.equal Index.equal left right )
;;
let tests ~count = [ alternative_right_distrib_1 count ]
end
module Suite_right_absorbtion_aux
(R : Model.COVARIANT_2)
(F : Preface_specs.INDEXED_ALTERNATIVE
with type ('a, 'index) t = ('a, 'index) R.t)
(A : Model.T0)
(B : Model.T0)
(Index : Model.T0) =
struct
module Laws = Preface_laws.Indexed_alternative.For_right_absorbtion (F)
let print pp = Format.asprintf "%a" (R.pp pp Index.pp)
let alternative_right_absorb_1 count =
let generator = R.generator A.generator Index.generator in
let print = print A.pp in
Util.test ~count ~print generator Laws.alternative_right_absorb_1
(fun lhs rhs x ->
let left = lhs x
and right = rhs x in
R.equal A.equal Index.equal left right )
;;
let tests ~count = [ alternative_right_absorb_1 count ]
end
module Suite_monoidal
(R : Model.COVARIANT_2)
(F : Preface_specs.INDEXED_ALTERNATIVE
with type ('a, 'index) t = ('a, 'index) R.t)
(A : Model.T0)
(B : Model.T0)
(C : Model.T0)
(Index : Model.T0) =
struct
module Applicative = Indexed_applicative.Suite (R) (F) (A) (B) (C) (Index)
module Alternative = Suite_monoidal_aux (R) (F) (A) (B) (Index)
let tests ~count = Applicative.tests ~count @ Alternative.tests ~count
end
module Suite_right_distributivity
(R : Model.COVARIANT_2)
(F : Preface_specs.INDEXED_ALTERNATIVE
with type ('a, 'index) t = ('a, 'index) R.t)
(A : Model.T0)
(B : Model.T0)
(C : Model.T0)
(Index : Model.T0) =
struct
module Applicative = Indexed_applicative.Suite (R) (F) (A) (B) (C) (Index)
module Alternative = Suite_right_distributivity_aux (R) (F) (A) (B) (Index)
let tests ~count = Applicative.tests ~count @ Alternative.tests ~count
end
module Suite_right_absorbtion
(R : Model.COVARIANT_2)
(F : Preface_specs.INDEXED_ALTERNATIVE
with type ('a, 'index) t = ('a, 'index) R.t)
(A : Model.T0)
(B : Model.T0)
(C : Model.T0)
(Index : Model.T0) =
struct
module Applicative = Indexed_applicative.Suite (R) (F) (A) (B) (C) (Index)
module Alternative = Suite_right_absorbtion_aux (R) (F) (A) (B) (Index)
let tests ~count = Applicative.tests ~count @ Alternative.tests ~count
end
module Suite
(R : Model.COVARIANT_2)
(F : Preface_specs.INDEXED_ALTERNATIVE
with type ('a, 'index) t = ('a, 'index) R.t)
(A : Model.T0)
(B : Model.T0)
(C : Model.T0)
(Index : Model.T0) =
struct
module Applicative = Indexed_applicative.Suite (R) (F) (A) (B) (C) (Index)
module Monoid = Suite_monoidal_aux (R) (F) (A) (B) (Index)
module Distrib = Suite_right_distributivity_aux (R) (F) (A) (B) (Index)
module Absorb = Suite_right_absorbtion_aux (R) (F) (A) (B) (Index)
let tests ~count =
Applicative.tests ~count
@ Monoid.tests ~count
@ Distrib.tests ~count
@ Absorb.tests ~count
;;
end