package preface

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

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

module Suite_monoidal_aux
    (R : Model.COVARIANT_1)
    (F : Preface_specs.ALTERNATIVE with type 'a t = 'a R.t)
    (A : Model.T0)
    (B : Model.T0) =
struct
  module Laws = Preface_laws.Alternative.For_monoidal (F)

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

  let alternative_monoid_1 count =
    let generator = R.generator A.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 left right )
  ;;

  let alternative_monoid_2 count =
    let generator = R.generator A.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 left right )
  ;;

  let alternative_monoid_3 count =
    let generator =
      Gen.tup3 (R.generator A.generator) (R.generator A.generator)
        (R.generator A.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 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_1)
    (F : Preface_specs.ALTERNATIVE with type 'a t = 'a R.t)
    (A : Model.T0)
    (B : Model.T0) =
struct
  module Laws = Preface_laws.Alternative.For_right_distributivity (F)

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

  let alternative_right_distrib_1 count =
    let generator =
      let f = R.generator (fun1 A.observable B.generator) in
      Gen.tup3 f f (R.generator A.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 left right )
  ;;

  let tests ~count = [ alternative_right_distrib_1 count ]
end

module Suite_right_absorbtion_aux
    (R : Model.COVARIANT_1)
    (F : Preface_specs.ALTERNATIVE with type 'a t = 'a R.t)
    (A : Model.T0)
    (B : Model.T0) =
struct
  module Laws = Preface_laws.Alternative.For_right_absorbtion (F)

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

  let alternative_right_absorb_1 count =
    let generator = R.generator A.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 left right )
  ;;

  let tests ~count = [ alternative_right_absorb_1 count ]
end

module Suite_monoidal
    (R : Model.COVARIANT_1)
    (F : Preface_specs.ALTERNATIVE with type 'a t = 'a R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0) =
struct
  module Applicative = Applicative.Suite (R) (F) (A) (B) (C)
  module Alternative = Suite_monoidal_aux (R) (F) (A) (B)

  let tests ~count = Applicative.tests ~count @ Alternative.tests ~count
end

module Suite_right_distributivity
    (R : Model.COVARIANT_1)
    (F : Preface_specs.ALTERNATIVE with type 'a t = 'a R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0) =
struct
  module Applicative = Applicative.Suite (R) (F) (A) (B) (C)
  module Alternative = Suite_right_distributivity_aux (R) (F) (A) (B)

  let tests ~count = Applicative.tests ~count @ Alternative.tests ~count
end

module Suite_right_absorbtion
    (R : Model.COVARIANT_1)
    (F : Preface_specs.ALTERNATIVE with type 'a t = 'a R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0) =
struct
  module Applicative = Applicative.Suite (R) (F) (A) (B) (C)
  module Alternative = Suite_right_absorbtion_aux (R) (F) (A) (B)

  let tests ~count = Applicative.tests ~count @ Alternative.tests ~count
end

module Suite
    (R : Model.COVARIANT_1)
    (F : Preface_specs.ALTERNATIVE with type 'a t = 'a R.t)
    (A : Model.T0)
    (B : Model.T0)
    (C : Model.T0) =
struct
  module Applicative = Applicative.Suite (R) (F) (A) (B) (C)
  module Monoid = Suite_monoidal_aux (R) (F) (A) (B)
  module Distrib = Suite_right_distributivity_aux (R) (F) (A) (B)
  module Absorb = Suite_right_absorbtion_aux (R) (F) (A) (B)

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

Innovation. Community. Security.