package preface

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

Source file indexed_monad_plus.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
open QCheck2

module Suite_monoidal_aux
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (Index : Model.T0) =
struct
  module Laws = Preface_laws.Indexed_monad_plus.For_monoidal (F)

  let print pp = Format.asprintf "%a" (R.pp pp Index.pp)

  let monad_plus_monoid_1 count =
    let generator = R.generator A.generator Index.generator in
    let print = print A.pp in
    Util.test ~count ~print generator Laws.monad_plus_monoid_1 (fun lhs rhs x ->
        let left = lhs x
        and right = rhs x in
        R.equal A.equal Index.equal left right )
  ;;

  let monad_plus_monoid_2 count =
    let generator = R.generator A.generator Index.generator in
    let print = print A.pp in
    Util.test ~count ~print generator Laws.monad_plus_monoid_2 (fun lhs rhs x ->
        let left = lhs x
        and right = rhs x in
        R.equal A.equal Index.equal left right )
  ;;

  let monad_plus_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.monad_plus_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 =
    [
      monad_plus_monoid_1 count
    ; monad_plus_monoid_2 count
    ; monad_plus_monoid_3 count
    ]
  ;;
end

module Suite_left_absorption_aux
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (Index : Model.T0) =
struct
  module Laws = Preface_laws.Indexed_monad_plus.For_left_absorption (F)

  let monad_plus_left_absorb_1 count =
    let generator =
      fun1 A.observable (R.generator B.generator Index.generator)
    in
    Util.test ~count generator Laws.monad_plus_left_absorb_1 (fun lhs rhs ff ->
        let f = Fn.apply ff in
        let left = lhs f
        and right = rhs f in
        R.equal B.equal Index.equal left right )
  ;;

  let tests ~count = [ monad_plus_left_absorb_1 count ]
end

module Suite_left_distributivity_aux
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (Index : Model.T0) =
struct
  module Laws = Preface_laws.Indexed_monad_plus.For_left_distributivity (F)

  let print pp = Format.asprintf "%a" (R.pp pp Index.pp)

  let monad_plus_left_distrib_1 count =
    let generator =
      Gen.tup3
        (R.generator A.generator Index.generator)
        (R.generator A.generator Index.generator)
        (fun1 A.observable (R.generator B.generator Index.generator))
    in
    let print (x, y, _) = Print.tup2 (print A.pp) (print A.pp) (x, y) in
    Util.test ~count ~print generator Laws.monad_plus_left_distrib_1
      (fun lhs rhs (x, y, ff) ->
        let f = Fn.apply ff in
        let left = lhs x y f
        and right = rhs x y f in
        R.equal B.equal Index.equal left right )
  ;;

  let tests ~count = [ monad_plus_left_distrib_1 count ]
end

module Suite_left_catch_aux
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (Index : Model.T0) =
struct
  module Laws = Preface_laws.Indexed_monad_plus.For_left_catch (F)

  let print pp = Format.asprintf "%a" (R.pp pp Index.pp)

  let monad_plus_left_catch count =
    let generator =
      Gen.tup2 A.generator (R.generator A.generator Index.generator)
    in
    let print = Print.tup2 (Format.asprintf "%a" A.pp) (print A.pp) in
    Util.test ~count ~print generator Laws.monad_plus_left_catch_1
      (fun lhs rhs (x, m) ->
        let left = lhs x m
        and right = rhs x m in
        R.equal A.equal Index.equal left right )
  ;;

  let tests ~count = [ monad_plus_left_catch count ]
end

module Suite_monoidal
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0)
    (D : Model.T0)
    (Index : Model.T0) =
struct
  module Monad = Indexed_monad.Suite (R) (F) (A) (B) (C) (D) (Index)
  module Monad_plus = Suite_monoidal_aux (R) (F) (A) (B) (Index)

  let tests ~count = Monad.tests ~count @ Monad_plus.tests ~count
end

module Suite_left_absorption
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0)
    (D : Model.T0)
    (Index : Model.T0) =
struct
  module Monad = Indexed_monad.Suite (R) (F) (A) (B) (C) (D) (Index)
  module Monad_plus = Suite_left_absorption_aux (R) (F) (A) (B) (Index)

  let tests ~count = Monad.tests ~count @ Monad_plus.tests ~count
end

module Suite_left_distributivity
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0)
    (D : Model.T0)
    (Index : Model.T0) =
struct
  module Monad = Indexed_monad.Suite (R) (F) (A) (B) (C) (D) (Index)
  module Monad_plus = Suite_left_distributivity_aux (R) (F) (A) (B) (Index)

  let tests ~count = Monad.tests ~count @ Monad_plus.tests ~count
end

module Suite_left_catch
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0)
    (D : Model.T0)
    (Index : Model.T0) =
struct
  module Monad = Indexed_monad.Suite (R) (F) (A) (B) (C) (D) (Index)
  module Monad_plus = Suite_left_catch_aux (R) (F) (A) (Index)

  let tests ~count = Monad.tests ~count @ Monad_plus.tests ~count
end

module Suite
    (R : Model.COVARIANT_2)
    (F : Preface_specs.INDEXED_MONAD_PLUS
           with type ('a, 'index) t = ('a, 'index) R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0)
    (D : Model.T0)
    (Index : Model.T0) =
struct
  module Monad = Indexed_monad.Suite (R) (F) (A) (B) (C) (D) (Index)
  module Monoid = Suite_monoidal_aux (R) (F) (A) (B) (Index)
  module Absorb = Suite_left_absorption_aux (R) (F) (A) (B) (Index)
  module Distrib = Suite_left_distributivity_aux (R) (F) (A) (B) (Index)
  module Catch = Suite_left_catch_aux (R) (F) (A) (Index)

  let tests ~count =
    Monad.tests ~count
    @ Monoid.tests ~count
    @ Absorb.tests ~count
    @ Distrib.tests ~count
    @ Catch.tests ~count
  ;;
end
OCaml

Innovation. Community. Security.