package caqti

  1. Overview
  2. Docs
Unified interface to relational database libraries

Install

dune-project
 Dependency

Authors

Maintainers

Sources

caqti-v2.3.2.tbz
sha256=8f6c1724b59ac22a5c657c9e53b9a1706e39ecd462e82958b0cea88e43f0aba7
sha512=75b968ab37ae94cadcaabbcce0f91b1ffa4334ed69e441bdeb823077eb7675264282efb0fab3baaaad446582cfb427769e19f22c8c194a316ac2248c3fba5cf8

doc/src/caqti.template/row_type.ml.html

Source file row_type.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
(* Copyright (C) 2017--2026  Petter A. Urkedal <paurkedal@gmail.com>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version, with the LGPL-3.0 Linking Exception.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * and the LGPL-3.0 Linking Exception along with this library.  If not, see
 * <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.
 *)

open Shims

type annot = [`Redacted] (* TODO: Consider open type. *)

module Private = struct
  type _ t =
    | Field : 'a Field_type.t -> 'a t
    | Option : 'a t -> 'a option t
    | Product : ('i, 'a) Constructor.t * ('i, 'a) product -> 'a t
    | Annot : annot * 'a t -> 'a t
  and (_, _) product =
    | Proj_end : ('a Constructor.return, 'a) product
    | Proj : 'b t * ('a -> 'b) * ('i, 'a) product -> ('b -> 'i, 'a) product
end
open Private

type 'a t = 'a Private.t
type ('i, 'a) product = ('i, 'a) Private.product

type any = Any : 'a t -> any

let rec unify : type a b. a t -> b t -> (a, b) Type.eq option =
  fun t1 t2 ->
  (match t1, t2 with
   | Field ft1, Field ft2 -> Field_type.unify ft1 ft2
   | Field _, _ | _, Field _ -> None
   | Option t1, Option t2 ->
      (match unify t1 t2 with
       | None -> None
       | Some Equal -> Some Equal)
   | Option _, _ | _, Option _ -> None
   | Product (name1, pt1), Product (name2, pt2) ->
      (match Constructor.unify name1 name2 with
       | Some dep -> unify_product pt1 pt2 dep
       | None -> None)
   | Product _, _ | _, Product _ -> None
   | Annot (`Redacted, t1), Annot (`Redacted, t2) -> unify t1 t2)
and unify_product
  : type i j a b. (i, a) product -> (j, b) product ->
    (i, j) Constructor.unifier -> (a, b) Type.eq option =
  fun pt1 pt2 deq ->
  (match pt1, pt2, deq with
   | Proj_end, Proj_end, Equal -> Some Type.Equal
   | Proj (t1, _, pt1), Proj (t2, _, pt2), Assume dep ->
      Option.bind (unify t1 t2) (fun p -> unify_product pt1 pt2 (dep p))
   | _ -> .)

(* length *)

let rec length : type a. a t -> int =
  (function
   | Field _ -> 1
   | Option t -> length t
   | Product (_, pt) -> length_product pt
   | Annot (_, t) -> length t)
and length_product : type a i. (i, a) product -> int =
  (function
   | Proj_end -> 0
   | Proj (t, _, pt) -> length t + length_product pt)

(* fields *)

let fields =
  let rec recurse
    : type a. a t -> Field_type.any Seq.t -> Field_type.any Seq.t =
    (function
     | Field ft -> fun cont () -> Seq.Cons (Field_type.Any ft, cont)
     | Option t -> recurse t
     | Product (_, pt) -> recurse_product pt
     | Annot (_, t) -> recurse t)
  and recurse_product
    : type a i. (i, a) product -> Field_type.any Seq.t -> Field_type.any Seq.t =
    (function
     | Proj_end -> Fun.id
     | Proj (t, _, pt) -> fun cont -> recurse t (recurse_product pt cont))
  in
  fun t -> recurse t Seq.empty

(* pp *)

let rec pp : type a. a t -> int -> Format.formatter -> unit -> unit =
  (function
   | Field ft ->
      let string_of_ft = Field_type.to_string ft in
      fun _ ppf () -> Format.pp_print_string ppf string_of_ft
   | Option t ->
      let pp_t = pp t 1 in
      fun _ ppf () -> Format.fprintf ppf "@[%a@ option@]" pp_t ()
   | Product (_, Proj_end) ->
      fun _ ppf () -> Format.pp_print_string ppf "unit"
   | Product (_, Proj (t0, _, pt)) ->
      let pp_t0 = pp t0 1 in
      let pp_pt = pp_product_tail pt in
      fun prec ->
        fun ppf () ->
          if prec > 0 then Format.pp_print_char ppf '(';
          pp_t0 ppf ();
          pp_pt ppf ();
          if prec > 0 then Format.pp_print_char ppf ')'
   | Annot (`Redacted, t) ->
      let pp_t = pp t 1 in
      fun _prec ppf () ->
        pp_t ppf ();
        Format.pp_print_string ppf " redacted")
and pp_product_tail
  : type a i. (i, a) product -> Format.formatter -> unit -> unit =
  (function
   | Proj_end -> fun _ () -> ()
   | Proj (t, _, pt) ->
      let pp_t = pp t 1 in
      let pp_pt = pp_product_tail pt in
      fun ppf () ->
        Format.pp_print_string ppf " × ";
        pp_t ppf ();
        pp_pt ppf ())

let pp ppf t = pp t 1 ppf ()
let pp_any ppf (Any t) = pp ppf t
let show t = Format.asprintf "%a" pp t

let field ft = Field ft

module type STD = sig
  val bool : bool t
  val int : int t
  val int16 : int t
  val int32 : int32 t
  val int64 : int64 t
  val float : float t
  val string : string t
  val octets : string t
  val pdate : Ptime.t t
  val ptime : Ptime.t t
  val ptime_span : Ptime.span t
  val option : 'a t -> 'a option t
  val redacted : 'a t -> 'a t
  val unit : unit t
  val t2 : 'a1 t -> 'a2 t -> ('a1 * 'a2) t
  val elim_t2 : ('a1 * 'a2) t -> ('a1 t * 'a2 t) option
  val t3 : 'a1 t -> 'a2 t -> 'a3 t -> ('a1 * 'a2 * 'a3) t
  val elim_t3 : ('a1 * 'a2 * 'a3) t -> ('a1 t * 'a2 t * 'a3 t) option
  val t4 : 'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> ('a1 * 'a2 * 'a3 * 'a4) t
  val elim_t4 :
    ('a1 * 'a2 * 'a3 * 'a4) t -> ('a1 t * 'a2 t * 'a3 t * 'a4 t) option
  val t5 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5) t
  val elim_t5 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t) option
  val t6 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t -> 'a6 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6) t
  val elim_t6 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t * 'a6 t) option
  val t7 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t -> 'a6 t -> 'a7 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7) t
  val elim_t7 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t * 'a6 t * 'a7 t) option
  val t8 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t -> 'a6 t -> 'a7 t -> 'a8 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8) t
  val elim_t8 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t * 'a6 t * 'a7 t * 'a8 t) option
  val t9 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t -> 'a6 t -> 'a7 t -> 'a8 t ->
    'a9 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9) t
  val elim_t9 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t * 'a6 t * 'a7 t * 'a8 t * 'a9 t)
      option
  val t10 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t -> 'a6 t -> 'a7 t -> 'a8 t ->
    'a9 t -> 'a10 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10) t
  val elim_t10 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t * 'a6 t * 'a7 t * 'a8 t * 'a9 t
      * 'a10 t) option
  val t11 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t -> 'a6 t -> 'a7 t -> 'a8 t ->
    'a9 t -> 'a10 t -> 'a11 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11) t
  val elim_t11 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t * 'a6 t * 'a7 t * 'a8 t * 'a9 t
      * 'a10 t * 'a11 t) option
  val t12 :
    'a1 t -> 'a2 t -> 'a3 t -> 'a4 t -> 'a5 t -> 'a6 t -> 'a7 t -> 'a8 t ->
    'a9 t -> 'a10 t -> 'a11 t -> 'a12 t ->
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11 * 'a12) t
  val elim_t12 :
    ('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11
      * 'a12) t ->
    ('a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t * 'a6 t * 'a7 t * 'a8 t * 'a9 t
      * 'a10 t * 'a11 t * 'a12 t) option
end

let option t = Option t

let rec product_unifier
  : type a i. (i, a) product -> (i, i) Constructor.unifier =
  let open Constructor in
  (function
   | Proj_end -> Equal
   | Proj (_, _, prod) -> Assume (fun Type.Equal -> product_unifier prod))

exception Reject of string

let product : type i a. i -> (i, a) product -> a t =
  fun intro prod ->
    let open struct
      open Constructor
      type (_, _) tag += Tag : (i, a) tag
      let unify_tag : type j b. (j, b) tag -> (i, j) unifier option =
        (function
         | Tag -> Some (product_unifier prod)
         | _ -> None)
      let ctor = {tag = Tag; unify_tag; construct = intro}
    end in
    Product (ctor, prod)

let product' ctor prod = Product (ctor, prod)

let proj t p prod = Proj (t, p, prod)
let proj_end = Proj_end

let enum ~encode ~decode name =
  product decode
    @@ proj (Field (Enum name)) encode
    @@ proj_end

let unit = product (Ok ()) proj_end

type (_, _) Constructor.tag +=
  | T2 : (
      'a0 -> 'a1 -> ('a0 * 'a1) Constructor.return,
      'a0 * 'a1
    ) Constructor.tag
  | T3 : (
      'a0 -> 'a1 -> 'a2 -> ('a0 * 'a1 * 'a2) Constructor.return,
      'a0 * 'a1 * 'a2
    ) Constructor.tag
  | T4 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 ->
      ('a0 * 'a1 * 'a2 * 'a3) Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3
    ) Constructor.tag
  | T5 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4) Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4
    ) Constructor.tag
  | T6 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5) Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5
    ) Constructor.tag
  | T7 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6) Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6
    ) Constructor.tag
  | T8 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7) Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7
    ) Constructor.tag
  | T9 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8)
        Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8
    ) Constructor.tag
  | T10 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9)
        Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9
    ) Constructor.tag
  | T11 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9 ->
      'a10 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10)
        Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10
    ) Constructor.tag
  | T12 : (
      'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9 ->
      'a10 -> 'a11 ->
      ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11)
        Constructor.return,
      'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11
    ) Constructor.tag

let t2 =
  let unify_tag
    : type j b a0 a1.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> (a0 * a1) Constructor.return, j) Constructor.unifier option =
    (function
     | T2 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal)))
     | _ -> None)
  in
  let construct x0 x1 = Ok (x0, x1) in
  fun t0 t1 ->
    product' {tag = T2; unify_tag; construct}
    @@ proj t0 fst
    @@ proj t1 snd
    @@ proj_end

let elim_t2 : type a0 a1. (a0 * a1) t -> (a0 t * a1 t) option =
  (function
   | Product ({tag = T2; _}, Proj (t0, _, Proj (t1, _, Proj_end))) ->
      Some (t0, t1)
   | _ -> None)

let t3 =
  let unify_tag
    : type j b a0 a1 a2.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> (a0 * a1 * a2) Constructor.return, j)
        Constructor.unifier option =
    (function
     | T3 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal))))
     | _ -> None)
  in
  let construct x0 x1 x2 = Ok (x0, x1, x2) in
  fun t0 t1 t2 ->
    product' {tag = T3; unify_tag; construct}
    @@ proj t0 (fun (x, _, _) -> x)
    @@ proj t1 (fun (_, x, _) -> x)
    @@ proj t2 (fun (_, _, x) -> x)
    @@ proj_end

let elim_t3 : type a0 a1 a2. (a0 * a1 * a2) t -> (a0 t * a1 t * a2 t) option =
  (function
   | Product ({tag = T3; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _, Proj_end)))) ->
      Some (t0, t1, t2)
   | _ -> None)

let t4 =
  let unify_tag
    : type j b a0 a1 a2 a3.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> (a0 * a1 * a2 * a3) Constructor.return, j)
        Constructor.unifier option =
    (function
     | T4 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal)))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 = Ok (x0, x1, x2, x3) in
  fun t0 t1 t2 t3 ->
    product' {tag = T4; unify_tag; construct}
    @@ proj t0 (fun (x, _, _, _) -> x)
    @@ proj t1 (fun (_, x, _, _) -> x)
    @@ proj t2 (fun (_, _, x, _) -> x)
    @@ proj t3 (fun (_, _, _, x) -> x)
    @@ proj_end

let elim_t4
  : type a0 a1 a2 a3.
    (a0 * a1 * a2 * a3) t -> (a0 t * a1 t * a2 t * a3 t) option =
  (function
   | Product ({tag = T4; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _, Proj_end))))) ->
      Some (t0, t1, t2, t3)
   | _ -> None)

let t5 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 ->
       (a0 * a1 * a2 * a3 * a4) Constructor.return, j)
        Constructor.unifier option =
    (function
     | T5 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal))))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 x4 = Ok (x0, x1, x2, x3, x4) in
  fun t0 t1 t2 t3 t4 ->
    product' {tag = T5; unify_tag; construct}
    @@ proj t0 (fun (x, _, _, _, _) -> x)
    @@ proj t1 (fun (_, x, _, _, _) -> x)
    @@ proj t2 (fun (_, _, x, _, _) -> x)
    @@ proj t3 (fun (_, _, _, x, _) -> x)
    @@ proj t4 (fun (_, _, _, _, x) -> x)
    @@ proj_end

let elim_t5
  : type a0 a1 a2 a3 a4.
    (a0 * a1 * a2 * a3 * a4) t -> (a0 t * a1 t * a2 t * a3 t * a4 t) option =
  (function
   | Product ({tag = T5; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _, Proj_end)))))) ->
      Some (t0, t1, t2, t3, t4)
   | _ -> None)

let t6 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4 a5.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 -> a5 ->
       (a0 * a1 * a2 * a3 * a4 * a5) Constructor.return, j)
        Constructor.unifier option =
    (function
     | T6 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal)))))))
     | _ -> None)
  in
  fun t0 t1 t2 t3 t4 t5 ->
    let construct x0 x1 x2 x3 x4 x5 = Ok (x0, x1, x2, x3, x4, x5) in
    product' {tag = T6; unify_tag; construct}
    @@ proj t0 (fun (x, _, _, _, _, _) -> x)
    @@ proj t1 (fun (_, x, _, _, _, _) -> x)
    @@ proj t2 (fun (_, _, x, _, _, _) -> x)
    @@ proj t3 (fun (_, _, _, x, _, _) -> x)
    @@ proj t4 (fun (_, _, _, _, x, _) -> x)
    @@ proj t5 (fun (_, _, _, _, _, x) -> x)
    @@ proj_end

let elim_t6
  : type a0 a1 a2 a3 a4 a5.
    (a0 * a1 * a2 * a3 * a4 * a5) t ->
    (a0 t * a1 t * a2 t * a3 t * a4 t * a5 t) option =
  (function
   | Product ({tag = T6; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _,
        Proj (t5, _, Proj_end))))))) ->
      Some (t0, t1, t2, t3, t4, t5)
   | _ -> None)

let t7 t0 t1 t2 t3 t4 t5 t6 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4 a5 a6.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 ->
       (a0 * a1 * a2 * a3 * a4 * a5 * a6) Constructor.return, j)
        Constructor.unifier option =
    (function
     | T7 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal))))))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 x4 x5 x6 = Ok (x0, x1, x2, x3, x4, x5, x6) in
  product' {tag = T7; unify_tag; construct}
  @@ proj t0 (fun (x, _, _, _, _, _, _) -> x)
  @@ proj t1 (fun (_, x, _, _, _, _, _) -> x)
  @@ proj t2 (fun (_, _, x, _, _, _, _) -> x)
  @@ proj t3 (fun (_, _, _, x, _, _, _) -> x)
  @@ proj t4 (fun (_, _, _, _, x, _, _) -> x)
  @@ proj t5 (fun (_, _, _, _, _, x, _) -> x)
  @@ proj t6 (fun (_, _, _, _, _, _, x) -> x)
  @@ proj_end

let elim_t7
  : type a0 a1 a2 a3 a4 a5 a6.
    (a0 * a1 * a2 * a3 * a4 * a5 * a6) t ->
    (a0 t * a1 t * a2 t * a3 t * a4 t * a5 t * a6 t) option =
  (function
   | Product ({tag = T7; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _,
        Proj (t5, _,
        Proj (t6, _, Proj_end)))))))) ->
      Some (t0, t1, t2, t3, t4, t5, t6)
   | _ -> None)

let t8 t0 t1 t2 t3 t4 t5 t6 t7 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4 a5 a6 a7.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 ->
       (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7) Constructor.return, j)
        Constructor.unifier option =
    (function
     | T8 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal)))))))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 x4 x5 x6 x7 = Ok (x0, x1, x2, x3, x4, x5, x6, x7) in
  product' {tag = T8; unify_tag; construct}
  @@ proj t0 (fun (x, _, _, _, _, _, _, _) -> x)
  @@ proj t1 (fun (_, x, _, _, _, _, _, _) -> x)
  @@ proj t2 (fun (_, _, x, _, _, _, _, _) -> x)
  @@ proj t3 (fun (_, _, _, x, _, _, _, _) -> x)
  @@ proj t4 (fun (_, _, _, _, x, _, _, _) -> x)
  @@ proj t5 (fun (_, _, _, _, _, x, _, _) -> x)
  @@ proj t6 (fun (_, _, _, _, _, _, x, _) -> x)
  @@ proj t7 (fun (_, _, _, _, _, _, _, x) -> x)
  @@ proj_end

let elim_t8
  : type a0 a1 a2 a3 a4 a5 a6 a7.
    (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7) t ->
    (a0 t * a1 t * a2 t * a3 t * a4 t * a5 t * a6 t * a7 t) option =
  (function
   | Product ({tag = T8; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _,
        Proj (t5, _,
        Proj (t6, _,
        Proj (t7, _, Proj_end))))))))) ->
      Some (t0, t1, t2, t3, t4, t5, t6, t7)
   | _ -> None)

let t9 t1 t2 t3 t4 t5 t6 t7 t8 t9 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4 a5 a6 a7 a8.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 ->
       (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8) Constructor.return, j)
        Constructor.unifier option =
    (function
     | T9 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal))))))))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 x4 x5 x6 x7 x8 =
    Ok (x0, x1, x2, x3, x4, x5, x6, x7, x8)
  in
  product' {tag = T9; unify_tag; construct}
  @@ proj t1 (fun (x, _, _, _, _, _, _, _, _) -> x)
  @@ proj t2 (fun (_, x, _, _, _, _, _, _, _) -> x)
  @@ proj t3 (fun (_, _, x, _, _, _, _, _, _) -> x)
  @@ proj t4 (fun (_, _, _, x, _, _, _, _, _) -> x)
  @@ proj t5 (fun (_, _, _, _, x, _, _, _, _) -> x)
  @@ proj t6 (fun (_, _, _, _, _, x, _, _, _) -> x)
  @@ proj t7 (fun (_, _, _, _, _, _, x, _, _) -> x)
  @@ proj t8 (fun (_, _, _, _, _, _, _, x, _) -> x)
  @@ proj t9 (fun (_, _, _, _, _, _, _, _, x) -> x)
  @@ proj_end

let elim_t9
  : type a0 a1 a2 a3 a4 a5 a6 a7 a8.
    (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8) t ->
    (a0 t * a1 t * a2 t * a3 t * a4 t * a5 t * a6 t * a7 t * a8 t) option =
  (function
   | Product ({tag = T9; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _,
        Proj (t5, _,
        Proj (t6, _,
        Proj (t7, _,
        Proj (t8, _, Proj_end)))))))))) ->
      Some (t0, t1, t2, t3, t4, t5, t6, t7, t8)
   | _ -> None)

let t10 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 ->
       (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 * a9)
         Constructor.return, j) Constructor.unifier option =
    (function
     | T10 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal)))))))))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 =
    Ok (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)
  in
  product' {tag = T10; unify_tag; construct}
  @@ proj t0 (fun (x, _, _, _, _, _, _, _, _, _) -> x)
  @@ proj t1 (fun (_, x, _, _, _, _, _, _, _, _) -> x)
  @@ proj t2 (fun (_, _, x, _, _, _, _, _, _, _) -> x)
  @@ proj t3 (fun (_, _, _, x, _, _, _, _, _, _) -> x)
  @@ proj t4 (fun (_, _, _, _, x, _, _, _, _, _) -> x)
  @@ proj t5 (fun (_, _, _, _, _, x, _, _, _, _) -> x)
  @@ proj t6 (fun (_, _, _, _, _, _, x, _, _, _) -> x)
  @@ proj t7 (fun (_, _, _, _, _, _, _, x, _, _) -> x)
  @@ proj t8 (fun (_, _, _, _, _, _, _, _, x, _) -> x)
  @@ proj t9 (fun (_, _, _, _, _, _, _, _, _, x) -> x)
  @@ proj_end

let elim_t10
  : type a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.
    (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 * a9) t ->
    (a0 t * a1 t * a2 t * a3 t * a4 t * a5 t * a6 t * a7 t * a8 t * a9 t)
      option =
  (function
   | Product ({tag = T10; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _,
        Proj (t5, _,
        Proj (t6, _,
        Proj (t7, _,
        Proj (t8, _,
        Proj (t9, _, Proj_end))))))))))) ->
      Some (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
   | _ -> None)

let t11 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 ->
       (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 * a9 * a10)
         Constructor.return, j) Constructor.unifier option =
    (function
     | T11 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal))))))))))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 =
    Ok (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)
  in
  product' {tag = T11; unify_tag; construct}
  @@ proj t0  (fun (x, _, _, _, _, _, _, _, _, _, _) -> x)
  @@ proj t1  (fun (_, x, _, _, _, _, _, _, _, _, _) -> x)
  @@ proj t2  (fun (_, _, x, _, _, _, _, _, _, _, _) -> x)
  @@ proj t3  (fun (_, _, _, x, _, _, _, _, _, _, _) -> x)
  @@ proj t4  (fun (_, _, _, _, x, _, _, _, _, _, _) -> x)
  @@ proj t5  (fun (_, _, _, _, _, x, _, _, _, _, _) -> x)
  @@ proj t6  (fun (_, _, _, _, _, _, x, _, _, _, _) -> x)
  @@ proj t7  (fun (_, _, _, _, _, _, _, x, _, _, _) -> x)
  @@ proj t8  (fun (_, _, _, _, _, _, _, _, x, _, _) -> x)
  @@ proj t9  (fun (_, _, _, _, _, _, _, _, _, x, _) -> x)
  @@ proj t10 (fun (_, _, _, _, _, _, _, _, _, _, x) -> x)
  @@ proj_end

let elim_t11
  : type a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10.
    (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 * a9 * a10) t ->
    (a0 t * a1 t * a2 t * a3 t * a4 t * a5 t * a6 t * a7 t * a8 t * a9 t
      * a10 t) option =
  (function
   | Product ({tag = T11; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _,
        Proj (t5, _,
        Proj (t6, _,
        Proj (t7, _,
        Proj (t8, _,
        Proj (t9, _,
        Proj (t10, _, Proj_end)))))))))))) ->
      Some (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)
   | _ -> None)

let t12 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 =
  let unify_tag
    : type j b a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11.
      (j, b) Constructor.tag ->
      (a0 -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> a11 ->
        (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 * a9 * a10 * a11)
          Constructor.return, j) Constructor.unifier option =
    (function
     | T12 ->
        Some (Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal ->
              Assume (fun Type.Equal -> Equal)))))))))))))
     | _ -> None)
  in
  let construct x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 =
    Ok (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11)
  in
  product' {tag = T12; unify_tag; construct}
  @@ proj t0  (fun (x, _, _, _, _, _, _, _, _, _, _, _) -> x)
  @@ proj t1  (fun (_, x, _, _, _, _, _, _, _, _, _, _) -> x)
  @@ proj t2  (fun (_, _, x, _, _, _, _, _, _, _, _, _) -> x)
  @@ proj t3  (fun (_, _, _, x, _, _, _, _, _, _, _, _) -> x)
  @@ proj t4  (fun (_, _, _, _, x, _, _, _, _, _, _, _) -> x)
  @@ proj t5  (fun (_, _, _, _, _, x, _, _, _, _, _, _) -> x)
  @@ proj t6  (fun (_, _, _, _, _, _, x, _, _, _, _, _) -> x)
  @@ proj t7  (fun (_, _, _, _, _, _, _, x, _, _, _, _) -> x)
  @@ proj t8  (fun (_, _, _, _, _, _, _, _, x, _, _, _) -> x)
  @@ proj t9  (fun (_, _, _, _, _, _, _, _, _, x, _, _) -> x)
  @@ proj t10 (fun (_, _, _, _, _, _, _, _, _, _, x, _) -> x)
  @@ proj t11 (fun (_, _, _, _, _, _, _, _, _, _, _, x) -> x)
  @@ proj_end

let elim_t12
  : type a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11.
    (a0 * a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 * a9 * a10 * a11) t ->
    (a0 t * a1 t * a2 t * a3 t * a4 t * a5 t * a6 t * a7 t * a8 t * a9 t
      * a10 t * a11 t) option =
  (function
   | Product ({tag = T12; _},
        Proj (t0, _,
        Proj (t1, _,
        Proj (t2, _,
        Proj (t3, _,
        Proj (t4, _,
        Proj (t5, _,
        Proj (t6, _,
        Proj (t7, _,
        Proj (t8, _,
        Proj (t9, _,
        Proj (t10, _,
        Proj (t11, _, Proj_end))))))))))))) ->
      Some (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11)
   | _ -> None)

let custom ~encode ~decode rep =
  let encode' x =
    (match encode x with
     | Ok y -> y
     | Error msg -> raise (Reject msg))
  in
  product decode @@ proj rep encode' @@ proj_end

let redacted t = Annot (`Redacted, t)

let bool = field Bool
let int = field Int
let int16 = field Int16
let int32 = field Int32
let int64 = field Int64
let float = field Float
let string = field String
let octets = field Octets
let pdate = field Pdate
let ptime = field Ptime
let ptime_span = field Ptime_span