-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstd_internal.ml
949 lines (770 loc) · 24 KB
/
std_internal.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
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
module Name_of = struct
let typename_of_int =
let module M =
Typename.Make0 (struct
type t = int
let name = "int"
end)
in
M.typename_of_t
;;
let typename_of_int32 =
let module M =
Typename.Make0 (struct
type t = int32
let name = "int32"
end)
in
M.typename_of_t
;;
let typename_of_int32_u =
let module M =
Typename.Make0 (struct
type t = unit -> int32
let name = "int32#"
end)
in
M.typename_of_t
;;
let typename_of_int64 =
let module M =
Typename.Make0 (struct
type t = int64
let name = "int64"
end)
in
M.typename_of_t
;;
let typename_of_int64_u =
let module M =
Typename.Make0 (struct
type t = unit -> int64
let name = "int64#"
end)
in
M.typename_of_t
;;
let typename_of_nativeint =
let module M =
Typename.Make0 (struct
type t = nativeint
let name = "nativeint"
end)
in
M.typename_of_t
;;
let typename_of_nativeint_u =
let module M =
Typename.Make0 (struct
type t = unit -> nativeint
let name = "nativeint#"
end)
in
M.typename_of_t
;;
let typename_of_char =
let module M =
Typename.Make0 (struct
type t = char
let name = "char"
end)
in
M.typename_of_t
;;
let typename_of_float =
let module M =
Typename.Make0 (struct
type t = float
let name = "float"
end)
in
M.typename_of_t
;;
let typename_of_float_u =
let module M =
Typename.Make0 (struct
type t = unit -> float
let name = "float#"
end)
in
M.typename_of_t
;;
let typename_of_string =
let module M =
Typename.Make0 (struct
type t = string
let name = "string"
end)
in
M.typename_of_t
;;
let typename_of_bytes =
let module M =
Typename.Make0 (struct
type t = bytes
let name = "bytes"
end)
in
M.typename_of_t
;;
let typename_of_bool =
let module M =
Typename.Make0 (struct
type t = bool
let name = "bool"
end)
in
M.typename_of_t
;;
let typename_of_unit =
let module M =
Typename.Make0 (struct
type t = unit
let name = "unit"
end)
in
M.typename_of_t
;;
module M_option = Typename.Make1 (struct
type 'a t = 'a option
let name = "option"
end)
let typename_of_option = M_option.typename_of_t
module M_list = Typename.Make1 (struct
type 'a t = 'a list
let name = "list"
end)
let typename_of_list = M_list.typename_of_t
module M_array = Typename.Make1 (struct
type 'a t = 'a array
let name = "array"
end)
let typename_of_array = M_array.typename_of_t
module M_lazy_t = Typename.Make1 (struct
type 'a t = 'a lazy_t
let name = "lazy_t"
end)
let typename_of_lazy_t = M_lazy_t.typename_of_t
module M_ref = Typename.Make1 (struct
type 'a t = 'a ref
let name = "ref"
end)
let typename_of_ref = M_ref.typename_of_t
module M_function = Typename.Make2 (struct
type ('a, 'b) t = 'a -> 'b
let name = "function"
end)
let typename_of_function = M_function.typename_of_t
type tuple0 = unit
module M_tuple0 = Typename.Make0 (struct
type t = tuple0
let name = "tuple0"
end)
let typename_of_tuple0 = M_tuple0.typename_of_t
module M_tuple2 = Typename.Make2 (struct
type ('a, 'b) t = 'a * 'b
let name = "tuple2"
end)
let typename_of_tuple2 = M_tuple2.typename_of_t
module M_tuple3 = Typename.Make3 (struct
type ('a, 'b, 'c) t = 'a * 'b * 'c
let name = "tuple3"
end)
let typename_of_tuple3 = M_tuple3.typename_of_t
module M_tuple4 = Typename.Make4 (struct
type ('a, 'b, 'c, 'd) t = 'a * 'b * 'c * 'd
let name = "tuple4"
end)
let typename_of_tuple4 = M_tuple4.typename_of_t
module M_tuple5 = Typename.Make5 (struct
type ('a, 'b, 'c, 'd, 'e) t = 'a * 'b * 'c * 'd * 'e
let name = "tuple5"
end)
let typename_of_tuple5 = M_tuple5.typename_of_t
end
module rec Typerep : sig
type value := [ `value ]
type non_value := [ `non_value ]
type (_, _) t_any =
| Int : (int, value) t_any
| Int32 : (int32, value) t_any
| Int64 : (int64, value) t_any
| Nativeint : (nativeint, value) t_any
| Char : (char, value) t_any
| Float : (float, value) t_any
| String : (string, value) t_any
| Bytes : (bytes, value) t_any
| Bool : (bool, value) t_any
| Unit : (unit, value) t_any
| Option : ('a, value) t_any -> ('a option, value) t_any
| List : ('a, value) t_any -> ('a list, value) t_any
| Array : ('a, value) t_any -> ('a array, value) t_any
| Lazy : ('a, value) t_any -> ('a lazy_t, value) t_any
| Ref : ('a, value) t_any -> ('a ref, value) t_any
| Function :
(('dom, value) t_any * ('rng, value) t_any)
-> ('dom -> 'rng, value) t_any
| Tuple : 'a Typerep.Tuple.t -> ('a, value) t_any
| Record : 'a Typerep.Record.t -> ('a, value) t_any
| Variant : 'a Typerep.Variant.t -> ('a, value) t_any
| Named : ('a Typerep.Named.t * ('a, value) t_any lazy_t option) -> ('a, value) t_any
| Int32_u : (unit -> int32, non_value) t_any
| Int64_u : (unit -> int64, non_value) t_any
| Nativeint_u : (unit -> nativeint, non_value) t_any
| Float_u : (unit -> float, non_value) t_any
type 'a t = ('a, value) t_any
type 'a t_non_value = (unit -> 'a, non_value) t_any
type 'a any_packed = T : ('a, _) t_any -> 'a any_packed
type packed = T : 'a t -> packed
module Named : sig
module type T0 = sig
type named
type t
val typename_of_named : named Typename.t
val typename_of_t : t Typename.t
val witness : (t, named) Type_equal.t
end
module type T1 = sig
type 'a named
type a
val a : a Typerep.t
type t
val typename_of_named : 'a Typename.t -> 'a named Typename.t
val typename_of_t : t Typename.t
val witness : (t, a named) Type_equal.t
end
module type T2 = sig
type ('a, 'b) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type t
val typename_of_named : 'a Typename.t -> 'b Typename.t -> ('a, 'b) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b) named) Type_equal.t
end
module type T3 = sig
type ('a, 'b, 'c) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type c
val c : c Typerep.t
type t
val typename_of_named
: 'a Typename.t
-> 'b Typename.t
-> 'c Typename.t
-> ('a, 'b, 'c) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b, c) named) Type_equal.t
end
module type T4 = sig
type ('a, 'b, 'c, 'd) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type c
val c : c Typerep.t
type d
val d : d Typerep.t
type t
val typename_of_named
: 'a Typename.t
-> 'b Typename.t
-> 'c Typename.t
-> 'd Typename.t
-> ('a, 'b, 'c, 'd) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b, c, d) named) Type_equal.t
end
module type T5 = sig
type ('a, 'b, 'c, 'd, 'e) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type c
val c : c Typerep.t
type d
val d : d Typerep.t
type e
val e : e Typerep.t
type t
val typename_of_named
: 'a Typename.t
-> 'b Typename.t
-> 'c Typename.t
-> 'd Typename.t
-> 'e Typename.t
-> ('a, 'b, 'c, 'd, 'e) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b, c, d, e) named) Type_equal.t
end
(* there the module is necessary because we need to deal with a type [t] with
parameters whose kind is not representable as a type variable: ['a 't], even with
a gadt. *)
type 'a t =
| T0 of (module T0 with type t = 'a)
| T1 of (module T1 with type t = 'a)
| T2 of (module T2 with type t = 'a)
| T3 of (module T3 with type t = 'a)
| T4 of (module T4 with type t = 'a)
| T5 of (module T5 with type t = 'a)
val arity : _ t -> int
val typename_of_t : 'a t -> 'a Typename.t
val name : _ t -> string
end
module Tuple : sig
(* these constructors could be plunged at toplevel of Typerep.t, however it is less
verbose that way *)
type _ t =
| T2 : (('a, _) Typerep.t_any * ('b, _) Typerep.t_any) -> ('a * 'b) t
| T3 :
(('a, _) Typerep.t_any * ('b, _) Typerep.t_any * ('c, _) Typerep.t_any)
-> ('a * 'b * 'c) t
| T4 :
(('a, _) Typerep.t_any
* ('b, _) Typerep.t_any
* ('c, _) Typerep.t_any
* ('d, _) Typerep.t_any)
-> ('a * 'b * 'c * 'd) t
| T5 :
(('a, _) Typerep.t_any
* ('b, _) Typerep.t_any
* ('c, _) Typerep.t_any
* ('d, _) Typerep.t_any
* ('e, _) Typerep.t_any)
-> ('a * 'b * 'c * 'd * 'e) t
val arity : _ t -> int
val typename_of_t : 'a t -> 'a Typename.t
end
include Variant_and_record_intf.S with type 'a t := 'a any_packed
val same : _ t_any -> _ t_any -> bool
val same_witness : ('a, _) t_any -> ('b, _) t_any -> ('a, 'b) Type_equal.t option
val same_witness_exn : ('a, _) t_any -> ('b, _) t_any -> ('a, 'b) Type_equal.t
val typename_of_t : ('a, _) t_any -> 'a Typename.t
val head : ('a, 'index) t_any -> ('a, 'index) t_any
end = struct
type value = [ `value ]
type non_value = [ `non_value ]
type (_, _) t_any =
| Int : (int, value) t_any
| Int32 : (int32, value) t_any
| Int64 : (int64, value) t_any
| Nativeint : (nativeint, value) t_any
| Char : (char, value) t_any
| Float : (float, value) t_any
| String : (string, value) t_any
| Bytes : (bytes, value) t_any
| Bool : (bool, value) t_any
| Unit : (unit, value) t_any
| Option : ('a, value) t_any -> ('a option, value) t_any
| List : ('a, value) t_any -> ('a list, value) t_any
| Array : ('a, value) t_any -> ('a array, value) t_any
| Lazy : ('a, value) t_any -> ('a lazy_t, value) t_any
| Ref : ('a, value) t_any -> ('a ref, value) t_any
| Function :
(('dom, value) t_any * ('rng, value) t_any)
-> ('dom -> 'rng, value) t_any
| Tuple : 'a Typerep.Tuple.t -> ('a, value) t_any
| Record : 'a Typerep.Record.t -> ('a, value) t_any
| Variant : 'a Typerep.Variant.t -> ('a, value) t_any
| Named : ('a Typerep.Named.t * ('a, value) t_any lazy_t option) -> ('a, value) t_any
| Int32_u : (unit -> int32, non_value) t_any
| Int64_u : (unit -> int64, non_value) t_any
| Nativeint_u : (unit -> nativeint, non_value) t_any
| Float_u : (unit -> float, non_value) t_any
type 'a t = ('a, value) t_any
type 'a t_non_value = (unit -> 'a, non_value) t_any
type 'a any_packed = T : ('a, _) t_any -> 'a any_packed
type packed = T : 'a t -> packed
module Named = struct
module type T0 = sig
type named
type t
val typename_of_named : named Typename.t
val typename_of_t : t Typename.t
val witness : (t, named) Type_equal.t
end
module type T1 = sig
type 'a named
type a
val a : a Typerep.t
type t
val typename_of_named : 'a Typename.t -> 'a named Typename.t
val typename_of_t : t Typename.t
val witness : (t, a named) Type_equal.t
end
module type T2 = sig
type ('a, 'b) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type t
val typename_of_named : 'a Typename.t -> 'b Typename.t -> ('a, 'b) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b) named) Type_equal.t
end
module type T3 = sig
type ('a, 'b, 'c) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type c
val c : c Typerep.t
type t
val typename_of_named
: 'a Typename.t
-> 'b Typename.t
-> 'c Typename.t
-> ('a, 'b, 'c) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b, c) named) Type_equal.t
end
module type T4 = sig
type ('a, 'b, 'c, 'd) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type c
val c : c Typerep.t
type d
val d : d Typerep.t
type t
val typename_of_named
: 'a Typename.t
-> 'b Typename.t
-> 'c Typename.t
-> 'd Typename.t
-> ('a, 'b, 'c, 'd) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b, c, d) named) Type_equal.t
end
module type T5 = sig
type ('a, 'b, 'c, 'd, 'e) named
type a
val a : a Typerep.t
type b
val b : b Typerep.t
type c
val c : c Typerep.t
type d
val d : d Typerep.t
type e
val e : e Typerep.t
type t
val typename_of_named
: 'a Typename.t
-> 'b Typename.t
-> 'c Typename.t
-> 'd Typename.t
-> 'e Typename.t
-> ('a, 'b, 'c, 'd, 'e) named Typename.t
val typename_of_t : t Typename.t
val witness : (t, (a, b, c, d, e) named) Type_equal.t
end
(* there the module is necessary because we need to deal with a type [t] with
parameters whose kind is not representable as a type variable: ['a 't], even with
a gadt. *)
type 'a t =
| T0 of (module T0 with type t = 'a)
| T1 of (module T1 with type t = 'a)
| T2 of (module T2 with type t = 'a)
| T3 of (module T3 with type t = 'a)
| T4 of (module T4 with type t = 'a)
| T5 of (module T5 with type t = 'a)
let arity = function
| T0 _ -> 0
| T1 _ -> 1
| T2 _ -> 2
| T3 _ -> 3
| T4 _ -> 4
| T5 _ -> 5
;;
let typename_of_t (type a) = function
| T0 rep ->
let module T = (val rep : T0 with type t = a) in
T.typename_of_t
| T1 rep ->
let module T = (val rep : T1 with type t = a) in
T.typename_of_t
| T2 rep ->
let module T = (val rep : T2 with type t = a) in
T.typename_of_t
| T3 rep ->
let module T = (val rep : T3 with type t = a) in
T.typename_of_t
| T4 rep ->
let module T = (val rep : T4 with type t = a) in
T.typename_of_t
| T5 rep ->
let module T = (val rep : T5 with type t = a) in
T.typename_of_t
;;
let name rep = Typename.Uid.name (Typename.uid (typename_of_t rep))
end
module Tuple = struct
(* these constructors could be plunged at toplevel of Typerep.t, however it is less
verbose this way *)
type _ t =
| T2 : (('a, _) Typerep.t_any * ('b, _) Typerep.t_any) -> ('a * 'b) t
| T3 :
(('a, _) Typerep.t_any * ('b, _) Typerep.t_any * ('c, _) Typerep.t_any)
-> ('a * 'b * 'c) t
| T4 :
(('a, _) Typerep.t_any
* ('b, _) Typerep.t_any
* ('c, _) Typerep.t_any
* ('d, _) Typerep.t_any)
-> ('a * 'b * 'c * 'd) t
| T5 :
(('a, _) Typerep.t_any
* ('b, _) Typerep.t_any
* ('c, _) Typerep.t_any
* ('d, _) Typerep.t_any
* ('e, _) Typerep.t_any)
-> ('a * 'b * 'c * 'd * 'e) t
let arity : type a. a t -> int = function
| Typerep.Tuple.T2 _ -> 2
| Typerep.Tuple.T3 _ -> 3
| Typerep.Tuple.T4 _ -> 4
| Typerep.Tuple.T5 _ -> 5
;;
let typename_of_t : type a. a t -> a Typename.t = function
| T2 (a, b) ->
Name_of.typename_of_tuple2 (Typerep.typename_of_t a) (Typerep.typename_of_t b)
| T3 (a, b, c) ->
Name_of.typename_of_tuple3
(Typerep.typename_of_t a)
(Typerep.typename_of_t b)
(Typerep.typename_of_t c)
| T4 (a, b, c, d) ->
Name_of.typename_of_tuple4
(Typerep.typename_of_t a)
(Typerep.typename_of_t b)
(Typerep.typename_of_t c)
(Typerep.typename_of_t d)
| T5 (a, b, c, d, e) ->
Name_of.typename_of_tuple5
(Typerep.typename_of_t a)
(Typerep.typename_of_t b)
(Typerep.typename_of_t c)
(Typerep.typename_of_t d)
(Typerep.typename_of_t e)
;;
end
include Variant_and_record_intf.M (struct
type 'a t = 'a any_packed
end)
let rec typename_of_t : type a index. (a, index) t_any -> a Typename.t = function
| Int -> Name_of.typename_of_int
| Int32 -> Name_of.typename_of_int32
| Int32_u -> Name_of.typename_of_int32_u
| Int64 -> Name_of.typename_of_int64
| Int64_u -> Name_of.typename_of_int64_u
| Nativeint -> Name_of.typename_of_nativeint
| Nativeint_u -> Name_of.typename_of_nativeint_u
| Char -> Name_of.typename_of_char
| Float -> Name_of.typename_of_float
| Float_u -> Name_of.typename_of_float_u
| String -> Name_of.typename_of_string
| Bytes -> Name_of.typename_of_bytes
| Bool -> Name_of.typename_of_bool
| Unit -> Name_of.typename_of_unit
| Option rep -> Name_of.typename_of_option (typename_of_t rep)
| List rep -> Name_of.typename_of_list (typename_of_t rep)
| Array rep -> Name_of.typename_of_array (typename_of_t rep)
| Lazy rep -> Name_of.typename_of_lazy_t (typename_of_t rep)
| Ref rep -> Name_of.typename_of_ref (typename_of_t rep)
| Function (dom, rng) ->
Name_of.typename_of_function (typename_of_t dom) (typename_of_t rng)
| Tuple rep -> Typerep.Tuple.typename_of_t rep
| Record rep -> Typerep.Record.typename_of_t rep
| Variant rep -> Typerep.Variant.typename_of_t rep
| Named (name, _) -> Named.typename_of_t name
;;
let rec same_witness
: type a b index1 index2.
(a, index1) t_any -> (b, index2) t_any -> (a, b) Type_equal.t option
=
fun t1 t2 ->
let module E = Type_equal in
match t1, t2 with
| Named (name1, r1), Named (name2, r2) ->
(match
Typename.same_witness (Named.typename_of_t name1) (Named.typename_of_t name2)
with
| Some E.T as x -> x
| None ->
(match r1, r2 with
| Some (lazy t1), Some (lazy t2) -> same_witness t1 t2
| Some (lazy t1), None -> same_witness t1 t2
| None, Some (lazy t2) -> same_witness t1 t2
| None, None -> None))
| Named (_, r1), t2 ->
(match r1 with
| Some (lazy t1) -> same_witness t1 t2
| None -> None)
| t1, Named (_, r2) ->
(match r2 with
| Some (lazy t2) -> same_witness t1 t2
| None -> None)
| Int, Int -> Some E.T
| Int32, Int32 -> Some E.T
| Int32_u, Int32_u -> Some E.T
| Int64, Int64 -> Some E.T
| Int64_u, Int64_u -> Some E.T
| Nativeint, Nativeint -> Some E.T
| Nativeint_u, Nativeint_u -> Some E.T
| Char, Char -> Some E.T
| Float, Float -> Some E.T
| Float_u, Float_u -> Some E.T
| String, String -> Some E.T
| Bytes, Bytes -> Some E.T
| Bool, Bool -> Some E.T
| Unit, Unit -> Some E.T
| Option r1, Option r2 ->
(match same_witness r1 r2 with
| None as x -> x
| Some E.T as x -> x)
| List r1, List r2 ->
(match same_witness r1 r2 with
| None as x -> x
| Some E.T as x -> x)
| Array r1, Array r2 ->
(match same_witness r1 r2 with
| None as x -> x
| Some E.T as x -> x)
| Lazy r1, Lazy r2 ->
(match same_witness r1 r2 with
| None as x -> x
| Some E.T as x -> x)
| Ref r1, Ref r2 ->
(match same_witness r1 r2 with
| None as x -> x
| Some E.T as x -> x)
| Function (dom1, rng1), Function (dom2, rng2) ->
(match same_witness dom1 dom2, same_witness rng1 rng2 with
| Some E.T, Some E.T -> Some E.T
| None, _ | _, None -> None)
| Tuple t1, Tuple t2 ->
let module T = Typerep.Tuple in
(match t1, t2 with
| T.T2 (a1, b1), T.T2 (a2, b2) ->
(match same_witness a1 a2, same_witness b1 b2 with
| Some E.T, Some E.T -> Some E.T
| None, _ | _, None -> None)
| T.T3 (a1, b1, c1), T.T3 (a2, b2, c2) ->
(match same_witness a1 a2, same_witness b1 b2, same_witness c1 c2 with
| Some E.T, Some E.T, Some E.T -> Some E.T
| None, _, _ | _, None, _ | _, _, None -> None)
| T.T4 (a1, b1, c1, d1), T.T4 (a2, b2, c2, d2) ->
(match
same_witness a1 a2, same_witness b1 b2, same_witness c1 c2, same_witness d1 d2
with
| Some E.T, Some E.T, Some E.T, Some E.T -> Some E.T
| None, _, _, _ | _, None, _, _ | _, _, None, _ | _, _, _, None -> None)
| T.T5 (a1, b1, c1, d1, e1), T.T5 (a2, b2, c2, d2, e2) ->
(match
( same_witness a1 a2
, same_witness b1 b2
, same_witness c1 c2
, same_witness d1 d2
, same_witness e1 e2 )
with
| Some E.T, Some E.T, Some E.T, Some E.T, Some E.T -> Some E.T
| None, _, _, _, _
| _, None, _, _, _
| _, _, None, _, _
| _, _, _, None, _
| _, _, _, _, None -> None)
| T.T2 _, _ -> None
| T.T3 _, _ -> None
| T.T4 _, _ -> None
| T.T5 _, _ -> None)
| Record r1, Record r2 ->
Typename.same_witness
(Typerep.Record.typename_of_t r1)
(Typerep.Record.typename_of_t r2)
| Variant r1, Variant r2 ->
Typename.same_witness
(Typerep.Variant.typename_of_t r1)
(Typerep.Variant.typename_of_t r2)
| Int, _ -> None
| Int32, _ -> None
| Int32_u, _ -> None
| Int64, _ -> None
| Int64_u, _ -> None
| Nativeint, _ -> None
| Nativeint_u, _ -> None
| Char, _ -> None
| Float, _ -> None
| Float_u, _ -> None
| String, _ -> None
| Bytes, _ -> None
| Bool, _ -> None
| Unit, _ -> None
| Option _, _ -> None
| List _, _ -> None
| Array _, _ -> None
| Lazy _, _ -> None
| Ref _, _ -> None
| Function _, _ -> None
| Tuple _, _ -> None
| Record _, _ -> None
| Variant _, _ -> None
;;
let same a b = same_witness a b <> None
let same_witness_exn a b =
match same_witness a b with
| Some proof -> proof
| None -> assert false
;;
let rec head : type a index. (a, index) t_any -> (a, index) t_any = function
| Typerep.Named (_, Some (lazy t)) -> head t
| t -> t
;;
end
let typerep_of_int = Typerep.Int
let typerep_of_int32 = Typerep.Int32
let typerep_of_int32_u = Typerep.Int32_u
let typerep_of_int64 = Typerep.Int64
let typerep_of_int64_u = Typerep.Int64_u
let typerep_of_nativeint = Typerep.Nativeint
let typerep_of_nativeint_u = Typerep.Nativeint_u
let typerep_of_char = Typerep.Char
let typerep_of_float = Typerep.Float
let typerep_of_float_u = Typerep.Float_u
let typerep_of_string = Typerep.String
let typerep_of_bytes = Typerep.Bytes
let typerep_of_bool = Typerep.Bool
let typerep_of_unit = Typerep.Unit
let typerep_of_option rep = Typerep.Option rep
let typerep_of_list rep = Typerep.List rep
let typerep_of_array rep = Typerep.Array rep
let typerep_of_lazy_t rep = Typerep.Lazy rep
let typerep_of_ref rep = Typerep.Ref rep
let typerep_of_function dom rng = Typerep.Function (dom, rng)
let typerep_of_tuple0 = Typerep.Unit
let typerep_of_tuple2 a b = Typerep.Tuple (Typerep.Tuple.T2 (a, b))
let typerep_of_tuple3 a b c = Typerep.Tuple (Typerep.Tuple.T3 (a, b, c))
let typerep_of_tuple4 a b c d = Typerep.Tuple (Typerep.Tuple.T4 (a, b, c, d))
let typerep_of_tuple5 a b c d e = Typerep.Tuple (Typerep.Tuple.T5 (a, b, c, d, e))
include Name_of
let value_tuple0 = ()
let typerep_of_int63, typename_of_int63 =
let typerep_and_typename_of_int63_repr
: type a b. (a, b) Base.Int63.Private.Repr.t -> a Typerep.t * a Typename.t
= function
| Base.Int63.Private.Repr.Int -> typerep_of_int, typename_of_int
| Base.Int63.Private.Repr.Int64 -> typerep_of_int64, typename_of_int64
in
typerep_and_typename_of_int63_repr Base.Int63.Private.repr
;;