package preface

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

Source file arrow_choice.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
open Preface_core.Shims

let extract = function Either.Left x | Either.Right x -> x

module Choose_over_left
    (Category : Preface_specs.Category.CORE)
    (Arrow : Preface_specs.Arrow.CORE with type ('a, 'b) t = ('a, 'b) Category.t)
    (Left : Preface_specs.Arrow_choice.WITH_LEFT
              with type ('a, 'b) t = ('a, 'b) Arrow.t) =
struct
  let choose f g =
    let ( >>> ) f g = Category.compose g f in
    Left.left f
    >>> Arrow.arrow Either.swap
    >>> Left.left g
    >>> Arrow.arrow Either.swap
  ;;
end

module Left_over_choose
    (Category : Preface_specs.Category.CORE)
    (Choose : Preface_specs.Arrow_choice.WITH_CHOOSE
                with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  let left x = Choose.choose x Category.id
end

module Core_over_category_and_via_arrow_and_fst_and_left
    (Category : Preface_specs.Category.CORE)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_FST_AND_LEFT
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  module C = Arrow.Core_over_category_and_via_arrow_and_fst (Category) (Req)
  include C

  let left = Req.left

  include Choose_over_left (Category) (C) (Req)
end

module Core_over_category_and_via_arrow_and_split_and_left
    (Category : Preface_specs.Category.CORE)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_SPLIT_AND_LEFT
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  module C = Arrow.Core_over_category_and_via_arrow_and_split (Category) (Req)
  include C

  let left = Req.left

  include Choose_over_left (Category) (C) (Req)
end

module Core_over_category_and_via_arrow_and_fst_and_choose
    (Category : Preface_specs.Category.CORE)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_FST_AND_CHOOSE
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  include Arrow.Core_over_category_and_via_arrow_and_fst (Category) (Req)

  let choose = Req.choose

  include Left_over_choose (Category) (Req)
end

module Core_over_category_and_via_arrow_and_split_and_choose
    (Category : Preface_specs.Category.CORE)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_SPLIT_AND_CHOOSE
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  include Arrow.Core_over_category_and_via_arrow_and_split (Category) (Req)

  let choose = Req.choose

  include Left_over_choose (Category) (Req)
end

module Operation_over_category
    (Category : Preface_specs.Category.OPERATION)
    (Core : Preface_specs.Arrow_choice.CORE
              with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  include Arrow.Operation_over_category (Category) (Core)

  let right x = Core.choose Core.id x
  let fan_in f g = Core.compose (Core.arrow extract) (Core.choose f g)
end

module Alias = Arrow.Alias

module Infix_over_category
    (Category : Preface_specs.Category.INFIX)
    (Core : Preface_specs.Arrow_choice.CORE
              with type ('a, 'b) t = ('a, 'b) Category.t)
    (Operation : Preface_specs.Arrow_choice.OPERATION
                   with type ('a, 'b) t = ('a, 'b) Core.t) =
struct
  include Arrow.Infix_over_category (Category) (Core) (Operation)

  let ( +++ ) = Core.choose
  let ( ||| ) = Operation.fan_in
end

module Via
    (Core : Preface_specs.Arrow_choice.CORE)
    (Operation : Preface_specs.Arrow_choice.OPERATION)
    (Alias : Preface_specs.Arrow_choice.ALIAS)
    (Infix : Preface_specs.Arrow_choice.INFIX) =
struct
  include Core
  include Operation
  include Alias
  include Infix
  module Infix = Infix
end

module Over_category_and_via_arrow_and_fst_and_left
    (Category : Preface_specs.CATEGORY)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_FST_AND_LEFT
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  module Core =
    Core_over_category_and_via_arrow_and_fst_and_left (Category) (Req)

  module Operation = Operation_over_category (Category) (Core)
  module Alias = Alias (Operation)
  module Infix = Infix_over_category (Category.Infix) (Core) (Operation)
  include Core
  include Operation
  include Alias
  include Infix
end

module Over_over_category_and_via_arrow_and_split_and_left
    (Category : Preface_specs.CATEGORY)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_SPLIT_AND_LEFT
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  module Core =
    Core_over_category_and_via_arrow_and_split_and_left (Category) (Req)

  module Operation = Operation_over_category (Category) (Core)
  module Alias = Alias (Operation)
  module Infix = Infix_over_category (Category.Infix) (Core) (Operation)
  include Core
  include Operation
  include Alias
  include Infix
end

module Over_category_and_via_arrow_and_fst_and_choose
    (Category : Preface_specs.CATEGORY)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_FST_AND_CHOOSE
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  module Core =
    Core_over_category_and_via_arrow_and_fst_and_choose (Category) (Req)

  module Operation = Operation_over_category (Category) (Core)
  module Alias = Alias (Operation)
  module Infix = Infix_over_category (Category.Infix) (Core) (Operation)
  include Core
  include Operation
  include Alias
  include Infix
end

module Over_category_and_via_arrow_and_split_and_choose
    (Category : Preface_specs.CATEGORY)
    (Req : Preface_specs.Arrow_choice.WITH_ARROW_AND_SPLIT_AND_CHOOSE
             with type ('a, 'b) t = ('a, 'b) Category.t) =
struct
  module Core =
    Core_over_category_and_via_arrow_and_split_and_choose (Category) (Req)

  module Operation = Operation_over_category (Category) (Core)
  module Alias = Alias (Operation)
  module Infix = Infix_over_category (Category) (Core) (Operation)
  include Core
  include Operation
  include Alias
  include Infix
end

module Over_arrow_with_left
    (Arrow : Preface_specs.ARROW)
    (Left : Preface_specs.Arrow_choice.WITH_LEFT
              with type ('a, 'b) t = ('a, 'b) Arrow.t) =
struct
  module Core_aux =
    Core_over_category_and_via_arrow_and_fst_and_left
      (Arrow)
      (struct
        include Arrow
        include Left
      end)

  module Operation_aux = Operation_over_category (Arrow) (Core_aux)
  module Infix_aux = Infix_over_category (Arrow) (Core_aux) (Operation_aux)
  include Core_aux
  include Operation_aux
  include Arrow

  module Infix = struct
    include Arrow.Infix
    include Infix_aux
  end

  include Infix
end

module Over_arrow_with_choose
    (Arrow : Preface_specs.ARROW)
    (Choose : Preface_specs.Arrow_choice.WITH_CHOOSE
                with type ('a, 'b) t = ('a, 'b) Arrow.t) =
struct
  module Core_aux =
    Core_over_category_and_via_arrow_and_fst_and_choose
      (Arrow)
      (struct
        include Arrow
        include Choose
      end)

  module Operation_aux = Operation_over_category (Arrow) (Core_aux)
  module Infix_aux = Infix_over_category (Arrow) (Core_aux) (Operation_aux)
  include Core_aux
  include Operation_aux
  include Arrow

  module Infix = struct
    include Arrow.Infix
    include Infix_aux
  end

  include Infix
end

module Over_arrow_with_left_and_choose
    (Arrow : Preface_specs.ARROW)
    (Choose_left : Preface_specs.Arrow_choice.WITH_LEFT_AND_CHOOSE
                     with type ('a, 'b) t = ('a, 'b) Arrow.t) =
struct
  module Core_aux = struct
    include Arrow
    include Choose_left
  end

  module Operation_aux = Operation_over_category (Arrow) (Core_aux)
  module Infix_aux = Infix_over_category (Arrow) (Core_aux) (Operation_aux)
  include Core_aux
  include Operation_aux
  include Arrow

  module Infix = struct
    include Arrow.Infix
    include Infix_aux
  end

  include Infix
end

module From_monad (Monad : Preface_specs.Monad.CORE) = struct
  module Arr = Arrow.From_monad (Monad)

  include
    Over_arrow_with_choose
      (Arr)
      (struct
        type ('a, 'b) t = 'a -> 'b Monad.t

        let choose f g =
          let left = Arr.(f >>> arrow Either.left)
          and right = Arr.(g >>> arrow Either.right) in
          Preface_core.Shims.Either.case left right
        ;;
      end)
end

module Product (F : Preface_specs.ARROW_CHOICE) (G : Preface_specs.ARROW_CHOICE) =
  Over_arrow_with_left
    (Arrow.Product (F) (G))
       (struct
         type ('a, 'b) t = ('a, 'b) F.t * ('a, 'b) G.t

         let left (x, y) = (F.left x, G.left y)
       end)
OCaml

Innovation. Community. Security.