package travesty

  1. Overview
  2. Docs
Traversable containers, monad extensions, and more

Install

Dune Dependency

Authors

Maintainers

Sources

travesty-0.8.0.tbz
sha256=216c920c872cef2d52fa58e3c49826766a2cf6f2233e64937f18c46c0c5c5388
sha512=3b4f76794666aa3fb16c3639479790df3478a79e6f582b3e66b144e57df26a76580499961dd374f4fb6f3bd2dd7506e2725ed1242bada9deb14eb1916cacd18f

doc/src/travesty/bi_mappable.ml.html

Source file bi_mappable.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
(* This file is part of 'travesty'.

   Copyright (c) 2018, 2019 by Matt Windsor

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   DEALINGS IN THE SOFTWARE. *)

open Base
open Bi_mappable_types

module Derived_ops_gen (I : Basic_generic) = struct
  let map_left (c : ('l1, 'r) I.t) ~(f : 'l1 I.left -> 'l2 I.left) :
      ('l2, 'r) I.t =
    I.bi_map c ~left:f ~right:Fn.id

  let map_right (c : ('l, 'r1) I.t) ~(f : 'r1 I.right -> 'r2 I.right) :
      ('l, 'r2) I.t =
    I.bi_map c ~left:Fn.id ~right:f
end

module Make0 (I : Basic0) :
  S0 with type t = I.t and type left = I.left and type right = I.right =
struct
  include I

  include Derived_ops_gen (struct
    type ('l, 'r) t = I.t

    type 'l left = I.left

    type 'r right = I.right

    let bi_map = I.bi_map
  end)
end

module Make1_left (I : Basic1_left) :
  S1_left with type 'l t = 'l I.t and type right = I.right = struct
  include I

  include Derived_ops_gen (struct
    type ('l, 'r) t = 'l I.t

    type 'l left = 'l

    type 'r right = I.right

    let bi_map = I.bi_map
  end)
end

module Make1_right (I : Basic1_right) :
  S1_right with type 'r t = 'r I.t and type left = I.left = struct
  include I

  include Derived_ops_gen (struct
    type ('l, 'r) t = 'r I.t

    type 'l left = I.left

    type 'r right = 'r

    let bi_map = I.bi_map
  end)
end

module Make2 (I : Basic2) : S2 with type ('l, 'r) t = ('l, 'r) I.t = struct
  include I

  include Derived_ops_gen (struct
    type ('l, 'r) t = ('l, 'r) I.t

    type 'l left = 'l

    type 'r right = 'r

    let bi_map = I.bi_map
  end)
end

module Fix2_left (I : Basic2) (Left : T) :
  S1_right with type 'r t = (Left.t, 'r) I.t and type left = Left.t =
Make1_right (struct
  type 'r t = (Left.t, 'r) I.t

  type left = Left.t

  let bi_map = I.bi_map
end)

module Fix2_right (I : Basic2) (Right : T) :
  S1_left with type 'l t = ('l, Right.t) I.t and type right = Right.t =
Make1_left (struct
  type 'l t = ('l, Right.t) I.t

  type right = Right.t

  let bi_map = I.bi_map
end)

module Fix2_both (I : Basic2) (Left : T) (Right : T) :
  S0
    with type t = (Left.t, Right.t) I.t
     and type left = Left.t
     and type right = Right.t = Make0 (struct
  type t = (Left.t, Right.t) I.t

  type left = Left.t

  type right = Right.t

  let bi_map = I.bi_map
end)

module Fix1_left (I : Basic1_left) (Left : T) :
  S0 with type t = Left.t I.t and type left = Left.t and type right = I.right =
Make0 (struct
  type t = Left.t I.t

  type left = Left.t

  type right = I.right

  let bi_map = I.bi_map
end)

module Fix1_right (I : Basic1_right) (Right : T) :
  S0
    with type t = Right.t I.t
     and type left = I.left
     and type right = Right.t = Make0 (struct
  type t = Right.t I.t

  type left = I.left

  type right = Right.t

  let bi_map = I.bi_map
end)

module Map1_left (I : S1_left) : Mappable_types.S1 with type 'l t = 'l I.t =
struct
  type 'l t = 'l I.t

  let map = I.map_left
end

module Map1_right (I : S1_right) :
  Mappable_types.S1 with type 'r t = 'r I.t = struct
  type 'r t = 'r I.t

  let map = I.map_right
end

module Map0_left (I : S0) :
  Mappable_types.S0 with type t = I.t and type elt = I.left = struct
  type t = I.t

  type elt = I.left

  let map = I.map_left
end

module Map0_right (I : S0) :
  Mappable_types.S0 with type t = I.t and type elt = I.right = struct
  type t = I.t

  type elt = I.right

  let map = I.map_right
end

module Chain_Bi2_Map1 (Bi : Basic2) (Map : Mappable_types.S1) :
  S2 with type ('l, 'r) t = ('l, 'r) Bi.t Map.t = Make2 (struct
  type ('l, 'r) t = ('l, 'r) Bi.t Map.t

  let bi_map (x : ('l1, 'r1) t) ~(left : 'l1 -> 'l2) ~(right : 'r1 -> 'r2) :
      ('l2, 'r2) t =
    Map.map x ~f:(Bi.bi_map ~left ~right)
end)

module Chain_Bi1_left_Map1 (Bi : Basic1_left) (Map : Mappable_types.S1) :
  S1_left with type 'l t = 'l Bi.t Map.t and type right = Bi.right =
Make1_left (struct
  type 'l t = 'l Bi.t Map.t

  type right = Bi.right

  let bi_map (x : 'l1 t) ~(left : 'l1 -> 'l2) ~(right : right -> right) :
      'l2 t =
    Map.map x ~f:(Bi.bi_map ~left ~right)
end)

module Chain_Bi1_right_Map1 (Bi : Basic1_right) (Map : Mappable_types.S1) :
  S1_right with type 'r t = 'r Bi.t Map.t and type left = Bi.left =
Make1_right (struct
  type 'r t = 'r Bi.t Map.t

  type left = Bi.left

  let bi_map (x : 'r1 t) ~(left : left -> left) ~(right : 'r1 -> 'r2) : 'r2 t
      =
    Map.map x ~f:(Bi.bi_map ~left ~right)
end)

module Chain_Bi0_Map1 (Bi : Basic0) (Map : Mappable_types.S1) :
  S0
    with type t = Bi.t Map.t
     and type left = Bi.left
     and type right = Bi.right = Make0 (struct
  type t = Bi.t Map.t

  type left = Bi.left

  type right = Bi.right

  let bi_map (x : t) ~(left : left -> left) ~(right : right -> right) : t =
    Map.map x ~f:(Bi.bi_map ~left ~right)
end)

module Chain_Map1_Bi2
    (LMap : Mappable_types.S1)
    (RMap : Mappable_types.S1)
    (Bi : Basic2) : S2 with type ('l, 'r) t = ('l LMap.t, 'r RMap.t) Bi.t =
Make2 (struct
  type ('l, 'r) t = ('l LMap.t, 'r RMap.t) Bi.t

  let bi_map (x : ('l1, 'r1) t) ~(left : 'l1 -> 'l2) ~(right : 'r1 -> 'r2) :
      ('l2, 'r2) t =
    Bi.bi_map x ~left:(LMap.map ~f:left) ~right:(RMap.map ~f:right)
end)

module Chain_Map1_Bi1_left (LMap : Mappable_types.S1) (Bi : Basic1_left) :
  S1_left with type 'l t = 'l LMap.t Bi.t and type right = Bi.right =
Make1_left (struct
  type 'l t = 'l LMap.t Bi.t

  type right = Bi.right

  let bi_map (x : 'l1 t) ~(left : 'l1 -> 'l2) ~(right : right -> right) :
      'l2 t =
    Bi.bi_map x ~left:(LMap.map ~f:left) ~right
end)

module Chain_Map1_Bi1_right (RMap : Mappable_types.S1) (Bi : Basic1_right) :
  S1_right with type 'r t = 'r RMap.t Bi.t and type left = Bi.left =
Make1_right (struct
  type 'r t = 'r RMap.t Bi.t

  type left = Bi.left

  let bi_map (x : 'r1 t) ~(left : left -> left) ~(right : 'r1 -> 'r2) : 'r2 t
      =
    Bi.bi_map x ~left ~right:(RMap.map ~f:right)
end)
OCaml

Innovation. Community. Security.