File: test.ml

package info (click to toggle)
ppx-compare 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: ml: 1,325; makefile: 14
file content (746 lines) | stat: -rw-r--r-- 19,929 bytes parent folder | download
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
open Ppx_compare_lib.Builtin

let failwith = `Should_refer_to_runtime_lib
let ignore = `Should_refer_to_runtime_lib
let ( = ) = `Should_refer_to_runtime_lib
let ( <> ) = `Should_refer_to_runtime_lib
let ( == ) = `Should_refer_to_runtime_lib
let ( != ) = `Should_refer_to_runtime_lib
let ( > ) = `Should_refer_to_runtime_lib
let ( < ) = `Should_refer_to_runtime_lib
let ( >= ) = `Should_refer_to_runtime_lib
let ( <= ) = `Should_refer_to_runtime_lib
let max = `Should_refer_to_runtime_lib
let min = `Should_refer_to_runtime_lib
let equal = `Should_refer_to_runtime_lib
let compare = `Should_refer_to_runtime_lib

module type M1_sig = sig
  type t [@@deriving_inline compare, equal, compare ~localize, equal ~localize]

  include sig
    [@@@ocaml.warning "-32"]

    include Ppx_compare_lib.Comparable.S with type t := t
    include Ppx_compare_lib.Equal.S with type t := t
    include Ppx_compare_lib.Comparable.S with type t := t
    include Ppx_compare_lib.Comparable.S_local with type t := t
    include Ppx_compare_lib.Equal.S with type t := t
    include Ppx_compare_lib.Equal.S_local with type t := t
  end
  [@@ocaml.doc "@inline"]

  [@@@end]
end

module type M1_sig_wrong_name = sig
  type t1 [@@deriving_inline compare, equal, compare ~localize, equal ~localize]

  include sig
    [@@@ocaml.warning "-32"]

    val compare_t1 : t1 -> t1 -> int
    val equal_t1 : t1 -> t1 -> bool
    val compare_t1 : t1 -> t1 -> int
    val compare_t1__local : t1 -> t1 -> int
    val equal_t1 : t1 -> t1 -> bool
    val equal_t1__local : t1 -> t1 -> bool
  end
  [@@ocaml.doc "@inline"]

  [@@@end]
end

module type M2_sig = sig
  type 'a t [@@deriving_inline compare, equal, compare ~localize, equal ~localize]

  include sig
    [@@@ocaml.warning "-32"]

    include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Comparable.S_local1 with type 'a t := 'a t
    include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Equal.S_local1 with type 'a t := 'a t
  end
  [@@ocaml.doc "@inline"]

  [@@@end]
end

module type M2_sig_wrong_name = sig
  type 'a t1 [@@deriving_inline compare, equal, compare ~localize, equal ~localize]

  include sig
    [@@@ocaml.warning "-32"]

    val compare_t1 : ('a -> 'a -> int) -> 'a t1 -> 'a t1 -> int
    val equal_t1 : ('a -> 'a -> bool) -> 'a t1 -> 'a t1 -> bool
    val compare_t1 : ('a -> 'a -> int) -> 'a t1 -> 'a t1 -> int
    val compare_t1__local : ('a -> 'a -> int) -> 'a t1 -> 'a t1 -> int
    val equal_t1 : ('a -> 'a -> bool) -> 'a t1 -> 'a t1 -> bool
    val equal_t1__local : ('a -> 'a -> bool) -> 'a t1 -> 'a t1 -> bool
  end
  [@@ocaml.doc "@inline"]

  [@@@end]
end

module M1 = struct
  type t = unit [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M2 = struct
  type t = int [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M3 = struct
  type t = bool [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M4 = struct
  type t = int32 [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M5 = struct
  type t = nativeint [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M6 = struct
  type t = int64 [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M7 = struct
  type t = float [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M8 = struct
  type t = bool * float [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M9 = struct
  type t = bool * float * int
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M10 = struct
  type t = bool * float * int * string
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M11 = struct
  type t = int ref [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M12 = struct
  type t = (float * float) option
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M13 = struct
  type t = float array [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M14 = struct
  type t = (int * int) array
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M15 = struct
  type t = float array array
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M16 = struct
  type t = int list [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M17 = struct
  type t =
    { s : string
    ; b : float array list
    ; mutable c : int * int64 option
    }
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M18 = struct
  type t =
    { a : float
    ; b : float
    ; c : float
    }
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M19 = struct
  type t = Foo [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M20 = struct
  type t = Foo of int [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M21 = struct
  type t = Foo of int * float
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M22 = struct
  type t =
    | Foo
    | Bar of int
    | Baz of string option
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M23 = struct
  type t =
    [ `Foo
    | `Bar of string * string
    ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M24 = struct
  type t = int * string * [ `Foo | `Bar ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M25 = struct
  (* no local comparison for String.t, only for string, so we don't test that *)
  type t = String.t [@@deriving compare, equal]
end

module type M26_sig = sig
  type 'a t [@@deriving_inline compare, equal, compare ~localize, equal ~localize]

  include sig
    [@@@ocaml.warning "-32"]

    include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Comparable.S_local1 with type 'a t := 'a t
    include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t
    include Ppx_compare_lib.Equal.S_local1 with type 'a t := 'a t
  end
  [@@ocaml.doc "@inline"]

  [@@@end]
end

module M26 = struct
  type 'a t = 'a array [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module MyList = struct
  type 'a t =
    | Nil
    | Node of 'a * 'a t
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M27 = struct
  type t = int [@@deriving compare, equal, compare ~localize, equal ~localize]

  module Inner = struct
    type nonrec t = t list [@@deriving compare, equal, compare ~localize, equal ~localize]

    let _ = ((compare : int list -> int list -> int) : t -> t -> int)
  end
end

module M28 = struct
  (* making sure that nobody is reversing the type parameters *)
  type ('a, 'b) t = ('a * 'b) list
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  let (_ : (int, float) t -> int) = [%compare: (int, float) t] [ 1, nan ]
end

module M29 = struct
  type t =
    | A of
        { a : float
        ; b : float
        ; c : float
        }
    | B of float * float * float
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module M30 = struct
  type ('a, 'b) t =
    | A of
        { a : 'a
        ; b : 'b
        ; c : float
        }
    | B of 'a * 'b
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module type Polyrec_sig = sig
  type ('a, 'b) t = T of ('a option, 'b) t [@@deriving_inline compare, equal]

  include sig
    [@@@ocaml.warning "-32"]

    include Ppx_compare_lib.Comparable.S2 with type ('a, 'b) t := ('a, 'b) t
    include Ppx_compare_lib.Equal.S2 with type ('a, 'b) t := ('a, 'b) t
  end
  [@@ocaml.doc "@inline"]

  [@@@end]

  type ('a, 'b) t1 = T of ('a option, 'b) t2

  and ('a, 'b) t2 =
    | T1 of ('a list, 'b) t1
    | T2 of ('a, 'b list) t2
  [@@deriving_inline compare, equal]

  include sig
    [@@@ocaml.warning "-32"]

    val compare_t1
      :  ('a -> 'a -> int)
      -> ('b -> 'b -> int)
      -> ('a, 'b) t1
      -> ('a, 'b) t1
      -> int

    val compare_t2
      :  ('a -> 'a -> int)
      -> ('b -> 'b -> int)
      -> ('a, 'b) t2
      -> ('a, 'b) t2
      -> int

    val equal_t1
      :  ('a -> 'a -> bool)
      -> ('b -> 'b -> bool)
      -> ('a, 'b) t1
      -> ('a, 'b) t1
      -> bool

    val equal_t2
      :  ('a -> 'a -> bool)
      -> ('b -> 'b -> bool)
      -> ('a, 'b) t2
      -> ('a, 'b) t2
      -> bool
  end
  [@@ocaml.doc "@inline"]

  [@@@end]
end

module Polyrec = struct
  type ('a, 'b) t = T of ('a option, 'b) t
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  type ('a, 'b) t1 = T of ('a option, 'b) t2

  and ('a, 'b) t2 =
    | T1 of ('a list, 'b) t1
    | T2 of ('a, 'b list) t2
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module type Variance_sig = sig
  type +'a t [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module Variance = struct
  type -'a t [@@deriving compare, equal, compare ~localize, equal ~localize]

  type (-'a, +'b) u = 'a t * 'b
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module Test = struct
  let ( = ) : int -> int -> bool = Base.Poly.( = )

  (* checking that for the types mentioned in the readme, we compare structurally  *)
  let%test _ = [%compare: unit option] None (Some ()) = Base.Poly.compare None (Some ())
  let%test _ = [%compare: unit list] [] [ () ] = Base.Poly.compare [] [ () ]

  let%test _ =
    [%compare: int array] [| 0; 1 |] [| 1 |] = Base.Poly.compare [| 0; 1 |] [| 1 |]
  ;;

  let%test _ =
    Base.Poly.( = )
      (List.sort [%compare: int option] [ Some 3; None; Some 2; Some 1 ])
      [ None; Some 1; Some 2; Some 3 ]
  ;;
end

module Variant_inclusion = struct
  type 'a type1 = [ `T1 of 'a ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  type 'a type2 =
    [ 'a type1
    | `T2
    ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  type 'a type3 =
    [ `T3
    | 'a type1
    ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  type 'a type4 =
    [ 'a type2
    | `T4
    | 'a type3
    ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  type 'a id = 'a [@@deriving compare, equal, compare ~localize, equal ~localize]

  type ('a, 'b) u = [ `u of 'a * 'b ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  type t = [ | (int, int) u ]
  [@@deriving compare, equal, compare ~localize, equal ~localize]
end

module Equal = struct
  let%test _ = [%compare.equal: int list] [ 7; 8; 9 ] [ 7; 8; 9 ]
  let%test _ = not ([%compare.equal: int list] [ 7; 8 ] [ 7; 8; 9 ])

  let%test _ =
    match [%compare: int * int] (1, 2) (1, 3) with
    | -1 -> true
    | _ -> false
  ;;

  let%test _ =
    match [%compare: int * int] (1, 3) (1, 2) with
    | 1 -> true
    | _ -> false
  ;;

  let%test _ = [%compare.equal: string option] None None
  let%test _ = not ([%compare.equal: string option] (Some "foo") None)
  let%test _ = [%compare.equal: string] "hello" "hello"
  let%test _ = not ([%compare.equal: string] "hello" "goodbye")
end

module Equal_local = struct
  let%test _ = [%compare_local.equal: int list] [ 7; 8; 9 ] [ 7; 8; 9 ]
  let%test _ = not ([%compare_local.equal: int list] [ 7; 8 ] [ 7; 8; 9 ])

  let%test _ =
    match [%compare_local: int * int] (1, 2) (1, 3) with
    | -1 -> true
    | _ -> false
  ;;

  let%test _ =
    match [%compare_local: int * int] (1, 3) (1, 2) with
    | 1 -> true
    | _ -> false
  ;;

  let%test _ = [%compare_local.equal: string option] None None
  let%test _ = not ([%compare_local.equal: string option] (Some "foo") None)
  let%test _ = [%compare_local.equal: string] "hello" "hello"
  let%test _ = not ([%compare_local.equal: string] "hello" "goodbye")
end

module Type_extensions : sig
  (* Making sure we don't generate [_ t -> _ t -> int], as
     that's too general. *)
  module type S = sig
    type 'a t

    val compare : [%compare: _ t]
    val equal : [%compare.equal: _ t]
    val compare__local : [%compare_local: _ t]
    val equal__local : [%compare_local.equal: _ t]
  end
end = struct
  module type S = sig
    type 'a t

    val compare : 'a t -> 'a t -> int
    val equal : 'a t -> 'a t -> bool
    val compare__local : 'a t -> 'a t -> int
    val equal__local : 'a t -> 'a t -> bool
  end
end

module Ignoring_field = struct
  type t =
    { a : int [@ignore]
    ; b : int
    ; c : int
    }
  [@@deriving_inline compare, equal]

  let _ = fun (_ : t) -> ()

  let compare =
    (fun a__1375_ b__1376_ ->
       if Stdlib.( == ) a__1375_ b__1376_
       then 0
       else (
         match compare_int a__1375_.b b__1376_.b with
         | 0 -> compare_int a__1375_.c b__1376_.c
         | n -> n)
      : t -> t -> int)
  ;;

  let _ = compare

  let equal =
    (fun a__1377_ b__1378_ ->
       if Stdlib.( == ) a__1377_ b__1378_
       then true
       else
         Stdlib.( && ) (equal_int a__1377_.b b__1378_.b) (equal_int a__1377_.c b__1378_.c)
      : t -> t -> bool)
  ;;

  let _ = equal

  [@@@deriving.end]

  let equal = [%compare.equal: t]
end

module Ignoring_inline = struct
  type t = int * int * int

  let compare = [%compare: _ * (int[@ignore]) * int]
  let _ = compare
  let equal = [%compare.equal: t]
  let%test _ = equal (0, 1, 2) (9, 1, 2)
  let%test _ = equal (0, 1, 2) (0, 9, 2)
  let%test _ = not (equal (0, 1, 2) (0, 1, 9))
end

module Ignoring = struct
  type t = { a : (int[@ignore]) * string } [@@deriving_inline compare, equal]

  let _ = fun (_ : t) -> ()

  let compare =
    (fun a__1395_ b__1396_ ->
       if Stdlib.( == ) a__1395_ b__1396_
       then 0
       else (
         let t__1397_, t__1398_ = a__1395_.a in
         let t__1399_, t__1400_ = b__1396_.a in
         match
           let (_ : _) = t__1397_
           and (_ : _) = t__1399_ in
           0
         with
         | 0 -> compare_string t__1398_ t__1400_
         | n -> n)
      : t -> t -> int)
  ;;

  let _ = compare

  let equal =
    (fun a__1401_ b__1402_ ->
       if Stdlib.( == ) a__1401_ b__1402_
       then true
       else (
         let t__1403_, t__1404_ = a__1401_.a in
         let t__1405_, t__1406_ = b__1402_.a in
         Stdlib.( && )
           (let (_ : _) = t__1403_
            and (_ : _) = t__1405_ in
            true)
           (equal_string t__1404_ t__1406_))
      : t -> t -> bool)
  ;;

  let _ = equal

  [@@@deriving.end]

  let%test _ = equal { a = 1, "hi" } { a = 2, "hi" }
  let%test _ = not (equal { a = 1, "hi" } { a = 1, "ho" })
end

module Ignoring_with_type = struct
  type t =
    { a : int
    ; b : (int[@compare.ignore])
    }
  [@@deriving_inline compare]

  let _ = fun (_ : t) -> ()

  let compare =
    (fun a__1407_ b__1408_ ->
       if Stdlib.( == ) a__1407_ b__1408_
       then 0
       else (
         match compare_int a__1407_.a b__1408_.a with
         | 0 ->
           let (_ : _) = a__1407_.b
           and (_ : _) = b__1408_.b in
           0
         | n -> n)
      : t -> t -> int)
  ;;

  let _ = compare

  [@@@deriving.end]
end

module Enum_optim = struct
  type t =
    | A
    | B
    | C
  [@@deriving_inline compare, equal]

  let _ = fun (_ : t) -> ()
  let compare = (Stdlib.compare : t -> t -> int)
  let _ = compare
  let equal = (Stdlib.( = ) : t -> t -> bool)
  let _ = equal

  [@@@deriving.end]
end

module Lazy_behavior = struct
  (* Test that the generated functions don't evaluate more than necessary *)
  type a = unit

  let equal_a () () = assert false
  let equal_a__local () () = assert false
  let compare_a () () = assert false
  let compare_a__local () () = assert false

  type b = int * a [@@deriving compare, equal, compare ~localize, equal ~localize]

  let%test _ = not (equal_b (0, ()) (1, ()))
  let%test _ = Base.Poly.( < ) (compare_b (0, ()) (1, ())) 0
end

module Not_ieee_compliant = struct
  type t = float [@@deriving compare, equal, compare ~localize, equal ~localize]

  let%test _ = [%equal: t] nan nan
  let%test _ = Base.Poly.( = ) ([%compare: t] nan nan) 0
end

module Wildcard : sig
  type _ transparent = int [@@deriving compare, equal, compare ~localize, equal ~localize]
  type _ opaque [@@deriving compare, equal, compare ~localize, equal ~localize]
end = struct
  type _ transparent = int [@@deriving compare, equal, compare ~localize, equal ~localize]

  let%test _ = [%equal: string transparent] 1 1
  let%test _ = not ([%equal: string transparent] 1 2)
  let%test _ = Base.Poly.( < ) ([%compare: string transparent] 1 2) 0
  let%test _ = Base.Poly.( = ) ([%compare: string transparent] 1 1) 0
  let%test _ = Base.Poly.( > ) ([%compare: string transparent] 2 1) 0

  type 'a opaque = 'a option
  [@@deriving compare, equal, compare ~localize, equal ~localize]

  let%test _ = [%equal: int opaque] (Some 1) (Some 1)
  let%test _ = not ([%equal: int opaque] None (Some 1))
  let%test _ = not ([%equal: int opaque] (Some 1) (Some 2))
  let%test _ = Base.Poly.( < ) ([%compare: int opaque] None (Some 1)) 0
  let%test _ = Base.Poly.( = ) ([%compare: int opaque] (Some 1) (Some 1)) 0
  let%test _ = Base.Poly.( > ) ([%compare: int opaque] (Some 2) (Some 1)) 0
end

module Local_with_aliased_comparisons : sig
  type t =
    | Int of int
    | Add of t * t
    | Sub of t * t
  [@@deriving_inline compare ~localize, equal ~localize]

  include sig
    [@@@ocaml.warning "-32"]

    include Ppx_compare_lib.Comparable.S with type t := t
    include Ppx_compare_lib.Comparable.S_local with type t := t
    include Ppx_compare_lib.Equal.S with type t := t
    include Ppx_compare_lib.Equal.S_local with type t := t
  end
  [@@ocaml.doc "@inline"]

  [@@@end]
end = struct
  type t =
    | Int of int
    | Add of t * t
    | Sub of t * t
  [@@deriving_inline compare ~localize, equal ~localize]

  let _ = fun (_ : t) -> ()

  let rec compare__local =
    (fun a__1541_ b__1542_ ->
       if Stdlib.( == ) a__1541_ b__1542_
       then 0
       else (
         match a__1541_, b__1542_ with
         | Int _a__1543_, Int _b__1544_ -> compare_int__local _a__1543_ _b__1544_
         | Int _, _ -> -1
         | _, Int _ -> 1
         | Add (_a__1545_, _a__1547_), Add (_b__1546_, _b__1548_) ->
           (match compare__local _a__1545_ _b__1546_ with
            | 0 -> compare__local _a__1547_ _b__1548_
            | n -> n)
         | Add _, _ -> -1
         | _, Add _ -> 1
         | Sub (_a__1549_, _a__1551_), Sub (_b__1550_, _b__1552_) ->
           (match compare__local _a__1549_ _b__1550_ with
            | 0 -> compare__local _a__1551_ _b__1552_
            | n -> n))
      : t -> t -> int)
  ;;

  let _ = compare__local
  let compare = (fun a b -> compare__local a b : t -> t -> int)
  let _ = compare

  let rec equal__local =
    (fun a__1553_ b__1554_ ->
       if Stdlib.( == ) a__1553_ b__1554_
       then true
       else (
         match a__1553_, b__1554_ with
         | Int _a__1555_, Int _b__1556_ -> equal_int__local _a__1555_ _b__1556_
         | Int _, _ -> false
         | _, Int _ -> false
         | Add (_a__1557_, _a__1559_), Add (_b__1558_, _b__1560_) ->
           Stdlib.( && )
             (equal__local _a__1557_ _b__1558_)
             (equal__local _a__1559_ _b__1560_)
         | Add _, _ -> false
         | _, Add _ -> false
         | Sub (_a__1561_, _a__1563_), Sub (_b__1562_, _b__1564_) ->
           Stdlib.( && )
             (equal__local _a__1561_ _b__1562_)
             (equal__local _a__1563_ _b__1564_))
      : t -> t -> bool)
  ;;

  let _ = equal__local
  let equal = (fun a b -> equal__local a b : t -> t -> bool)
  let _ = equal

  [@@@end]
end