| 1 |
open Ppx_compare_lib.Builtin |
| 2 |
|
| 3 |
let failwith = `Should_refer_to_runtime_lib |
| 4 |
let ignore = `Should_refer_to_runtime_lib |
| 5 |
let ( = ) = `Should_refer_to_runtime_lib |
| 6 |
let ( <> ) = `Should_refer_to_runtime_lib |
| 7 |
let ( == ) = `Should_refer_to_runtime_lib |
| 8 |
let ( != ) = `Should_refer_to_runtime_lib |
| 9 |
let ( > ) = `Should_refer_to_runtime_lib |
| 10 |
let ( < ) = `Should_refer_to_runtime_lib |
| 11 |
let ( >= ) = `Should_refer_to_runtime_lib |
| 12 |
let ( <= ) = `Should_refer_to_runtime_lib |
| 13 |
let max = `Should_refer_to_runtime_lib |
| 14 |
let min = `Should_refer_to_runtime_lib |
| 15 |
let equal = `Should_refer_to_runtime_lib |
| 16 |
let compare = `Should_refer_to_runtime_lib |
| 17 |
|
| 18 |
module type M1_sig = sig |
| 19 |
type t [@@deriving_inline compare, equal, compare ~localize, equal ~localize] |
| 20 |
|
| 21 |
include sig |
| 22 |
[@@@ocaml.warning "-32"] |
| 23 |
|
| 24 |
include Ppx_compare_lib.Comparable.S with type t := t |
| 25 |
include Ppx_compare_lib.Equal.S with type t := t |
| 26 |
include Ppx_compare_lib.Comparable.S with type t := t |
| 27 |
include Ppx_compare_lib.Comparable.S_local with type t := t |
| 28 |
include Ppx_compare_lib.Equal.S with type t := t |
| 29 |
include Ppx_compare_lib.Equal.S_local with type t := t |
| 30 |
end |
| 31 |
[@@ocaml.doc "@inline"] |
| 32 |
|
| 33 |
[@@@end] |
| 34 |
end |
| 35 |
|
| 36 |
module type M1_sig_wrong_name = sig |
| 37 |
type t1 [@@deriving_inline compare, equal, compare ~localize, equal ~localize] |
| 38 |
|
| 39 |
include sig |
| 40 |
[@@@ocaml.warning "-32"] |
| 41 |
|
| 42 |
val compare_t1 : t1 -> t1 -> int |
| 43 |
val equal_t1 : t1 -> t1 -> bool |
| 44 |
val compare_t1 : t1 -> t1 -> int |
| 45 |
val compare_t1__local : t1 -> t1 -> int |
| 46 |
val equal_t1 : t1 -> t1 -> bool |
| 47 |
val equal_t1__local : t1 -> t1 -> bool |
| 48 |
end |
| 49 |
[@@ocaml.doc "@inline"] |
| 50 |
|
| 51 |
[@@@end] |
| 52 |
end |
| 53 |
|
| 54 |
module type M2_sig = sig |
| 55 |
type 'a t [@@deriving_inline compare, equal, compare ~localize, equal ~localize] |
| 56 |
|
| 57 |
include sig |
| 58 |
[@@@ocaml.warning "-32"] |
| 59 |
|
| 60 |
include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t |
| 61 |
include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t |
| 62 |
include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t |
| 63 |
include Ppx_compare_lib.Comparable.S_local1 with type 'a t := 'a t |
| 64 |
include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t |
| 65 |
include Ppx_compare_lib.Equal.S_local1 with type 'a t := 'a t |
| 66 |
end |
| 67 |
[@@ocaml.doc "@inline"] |
| 68 |
|
| 69 |
[@@@end] |
| 70 |
end |
| 71 |
|
| 72 |
module type M2_sig_wrong_name = sig |
| 73 |
type 'a t1 [@@deriving_inline compare, equal, compare ~localize, equal ~localize] |
| 74 |
|
| 75 |
include sig |
| 76 |
[@@@ocaml.warning "-32"] |
| 77 |
|
| 78 |
val compare_t1 : ('a -> 'a -> int) -> 'a t1 -> 'a t1 -> int |
| 79 |
val equal_t1 : ('a -> 'a -> bool) -> 'a t1 -> 'a t1 -> bool |
| 80 |
val compare_t1 : ('a -> 'a -> int) -> 'a t1 -> 'a t1 -> int |
| 81 |
val compare_t1__local : ('a -> 'a -> int) -> 'a t1 -> 'a t1 -> int |
| 82 |
val equal_t1 : ('a -> 'a -> bool) -> 'a t1 -> 'a t1 -> bool |
| 83 |
val equal_t1__local : ('a -> 'a -> bool) -> 'a t1 -> 'a t1 -> bool |
| 84 |
end |
| 85 |
[@@ocaml.doc "@inline"] |
| 86 |
|
| 87 |
[@@@end] |
| 88 |
end |
| 89 |
|
| 90 |
module M1 = struct |
| 91 |
type t = unit [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 92 |
end |
| 93 |
|
| 94 |
module M2 = struct |
| 95 |
type t = int [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 96 |
end |
| 97 |
|
| 98 |
module M3 = struct |
| 99 |
type t = bool [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 100 |
end |
| 101 |
|
| 102 |
module M4 = struct |
| 103 |
type t = int32 [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 104 |
end |
| 105 |
|
| 106 |
module M5 = struct |
| 107 |
type t = nativeint [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 108 |
end |
| 109 |
|
| 110 |
module M6 = struct |
| 111 |
type t = int64 [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 112 |
end |
| 113 |
|
| 114 |
module M7 = struct |
| 115 |
type t = float [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 116 |
end |
| 117 |
|
| 118 |
module M8 = struct |
| 119 |
type t = bool * float [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 120 |
end |
| 121 |
|
| 122 |
module M9 = struct |
| 123 |
type t = bool * float * int |
| 124 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 125 |
end |
| 126 |
|
| 127 |
module M10 = struct |
| 128 |
type t = bool * float * int * string |
| 129 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 130 |
end |
| 131 |
|
| 132 |
module M11 = struct |
| 133 |
type t = int ref [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 134 |
end |
| 135 |
|
| 136 |
module M12 = struct |
| 137 |
type t = (float * float) option |
| 138 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 139 |
end |
| 140 |
|
| 141 |
module M13 = struct |
| 142 |
type t = float array [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 143 |
end |
| 144 |
|
| 145 |
module M14 = struct |
| 146 |
type t = (int * int) array |
| 147 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 148 |
end |
| 149 |
|
| 150 |
module M15 = struct |
| 151 |
type t = float array array |
| 152 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 153 |
end |
| 154 |
|
| 155 |
module M16 = struct |
| 156 |
type t = int list [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 157 |
end |
| 158 |
|
| 159 |
module M17 = struct |
| 160 |
type t = |
| 161 |
{ s : string |
| 162 |
; b : float array list |
| 163 |
; mutable c : int * int64 option |
| 164 |
} |
| 165 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 166 |
end |
| 167 |
|
| 168 |
module M18 = struct |
| 169 |
type t = |
| 170 |
{ a : float |
| 171 |
; b : float |
| 172 |
; c : float |
| 173 |
} |
| 174 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 175 |
end |
| 176 |
|
| 177 |
module M19 = struct |
| 178 |
type t = Foo [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 179 |
end |
| 180 |
|
| 181 |
module M20 = struct |
| 182 |
type t = Foo of int [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 183 |
end |
| 184 |
|
| 185 |
module M21 = struct |
| 186 |
type t = Foo of int * float |
| 187 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 188 |
end |
| 189 |
|
| 190 |
module M22 = struct |
| 191 |
type t = |
| 192 |
| Foo |
| 193 |
| Bar of int |
| 194 |
| Baz of string option |
| 195 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 196 |
end |
| 197 |
|
| 198 |
module M23 = struct |
| 199 |
type t = |
| 200 |
[ `Foo |
| 201 |
| `Bar of string * string |
| 202 |
] |
| 203 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 204 |
end |
| 205 |
|
| 206 |
module M24 = struct |
| 207 |
type t = int * string * [ `Foo | `Bar ] |
| 208 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 209 |
end |
| 210 |
|
| 211 |
module M25 = struct |
| 212 |
|
| 213 |
type t = String.t [@@deriving compare, equal] |
| 214 |
end |
| 215 |
|
| 216 |
module type M26_sig = sig |
| 217 |
type 'a t [@@deriving_inline compare, equal, compare ~localize, equal ~localize] |
| 218 |
|
| 219 |
include sig |
| 220 |
[@@@ocaml.warning "-32"] |
| 221 |
|
| 222 |
include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t |
| 223 |
include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t |
| 224 |
include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t |
| 225 |
include Ppx_compare_lib.Comparable.S_local1 with type 'a t := 'a t |
| 226 |
include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t |
| 227 |
include Ppx_compare_lib.Equal.S_local1 with type 'a t := 'a t |
| 228 |
end |
| 229 |
[@@ocaml.doc "@inline"] |
| 230 |
|
| 231 |
[@@@end] |
| 232 |
end |
| 233 |
|
| 234 |
module M26 = struct |
| 235 |
type 'a t = 'a array [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 236 |
end |
| 237 |
|
| 238 |
module MyList = struct |
| 239 |
type 'a t = |
| 240 |
| Nil |
| 241 |
| Node of 'a * 'a t |
| 242 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 243 |
end |
| 244 |
|
| 245 |
module M27 = struct |
| 246 |
type t = int [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 247 |
|
| 248 |
module Inner = struct |
| 249 |
type nonrec t = t list [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 250 |
|
| 251 |
let _ = ((compare : int list -> int list -> int) : t -> t -> int) |
| 252 |
end |
| 253 |
end |
| 254 |
|
| 255 |
module M28 = struct |
| 256 |
|
| 257 |
type ('a, 'b) t = ('a * 'b) list |
| 258 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 259 |
|
| 260 |
let (_ : (int, float) t -> int) = [%compare: (int, float) t] [ 1, nan ] |
| 261 |
end |
| 262 |
|
| 263 |
module M29 = struct |
| 264 |
type t = |
| 265 |
| A of |
| 266 |
{ a : float |
| 267 |
; b : float |
| 268 |
; c : float |
| 269 |
} |
| 270 |
| B of float * float * float |
| 271 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 272 |
end |
| 273 |
|
| 274 |
module M30 = struct |
| 275 |
type ('a, 'b) t = |
| 276 |
| A of |
| 277 |
{ a : 'a |
| 278 |
; b : 'b |
| 279 |
; c : float |
| 280 |
} |
| 281 |
| B of 'a * 'b |
| 282 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 283 |
end |
| 284 |
|
| 285 |
module type Polyrec_sig = sig |
| 286 |
type ('a, 'b) t = T of ('a option, 'b) t [@@deriving_inline compare, equal] |
| 287 |
|
| 288 |
include sig |
| 289 |
[@@@ocaml.warning "-32"] |
| 290 |
|
| 291 |
include Ppx_compare_lib.Comparable.S2 with type ('a, 'b) t := ('a, 'b) t |
| 292 |
include Ppx_compare_lib.Equal.S2 with type ('a, 'b) t := ('a, 'b) t |
| 293 |
end |
| 294 |
[@@ocaml.doc "@inline"] |
| 295 |
|
| 296 |
[@@@end] |
| 297 |
|
| 298 |
type ('a, 'b) t1 = T of ('a option, 'b) t2 |
| 299 |
|
| 300 |
and ('a, 'b) t2 = |
| 301 |
| T1 of ('a list, 'b) t1 |
| 302 |
| T2 of ('a, 'b list) t2 |
| 303 |
[@@deriving_inline compare, equal] |
| 304 |
|
| 305 |
include sig |
| 306 |
[@@@ocaml.warning "-32"] |
| 307 |
|
| 308 |
val compare_t1 |
| 309 |
: ('a -> 'a -> int) |
| 310 |
-> ('b -> 'b -> int) |
| 311 |
-> ('a, 'b) t1 |
| 312 |
-> ('a, 'b) t1 |
| 313 |
-> int |
| 314 |
|
| 315 |
val compare_t2 |
| 316 |
: ('a -> 'a -> int) |
| 317 |
-> ('b -> 'b -> int) |
| 318 |
-> ('a, 'b) t2 |
| 319 |
-> ('a, 'b) t2 |
| 320 |
-> int |
| 321 |
|
| 322 |
val equal_t1 |
| 323 |
: ('a -> 'a -> bool) |
| 324 |
-> ('b -> 'b -> bool) |
| 325 |
-> ('a, 'b) t1 |
| 326 |
-> ('a, 'b) t1 |
| 327 |
-> bool |
| 328 |
|
| 329 |
val equal_t2 |
| 330 |
: ('a -> 'a -> bool) |
| 331 |
-> ('b -> 'b -> bool) |
| 332 |
-> ('a, 'b) t2 |
| 333 |
-> ('a, 'b) t2 |
| 334 |
-> bool |
| 335 |
end |
| 336 |
[@@ocaml.doc "@inline"] |
| 337 |
|
| 338 |
[@@@end] |
| 339 |
end |
| 340 |
|
| 341 |
module Polyrec = struct |
| 342 |
type ('a, 'b) t = T of ('a option, 'b) t |
| 343 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 344 |
|
| 345 |
type ('a, 'b) t1 = T of ('a option, 'b) t2 |
| 346 |
|
| 347 |
and ('a, 'b) t2 = |
| 348 |
| T1 of ('a list, 'b) t1 |
| 349 |
| T2 of ('a, 'b list) t2 |
| 350 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 351 |
end |
| 352 |
|
| 353 |
module type Variance_sig = sig |
| 354 |
type +'a t [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 355 |
end |
| 356 |
|
| 357 |
module Variance = struct |
| 358 |
type -'a t [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 359 |
|
| 360 |
type (-'a, +'b) u = 'a t * 'b |
| 361 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 362 |
end |
| 363 |
|
| 364 |
module Test = struct |
| 365 |
let ( = ) : int -> int -> bool = Base.Poly.( = ) |
| 366 |
|
| 367 |
|
| 368 |
let%test _ = [%compare: unit option] None (Some ()) = Base.Poly.compare None (Some ()) |
| 369 |
let%test _ = [%compare: unit list] [] [ () ] = Base.Poly.compare [] [ () ] |
| 370 |
|
| 371 |
let%test _ = |
| 372 |
[%compare: int array] [| 0; 1 |] [| 1 |] = Base.Poly.compare [| 0; 1 |] [| 1 |] |
| 373 |
;; |
| 374 |
|
| 375 |
let%test _ = |
| 376 |
Base.Poly.( = ) |
| 377 |
(List.sort [%compare: int option] [ Some 3; None; Some 2; Some 1 ]) |
| 378 |
[ None; Some 1; Some 2; Some 3 ] |
| 379 |
;; |
| 380 |
end |
| 381 |
|
| 382 |
module Variant_inclusion = struct |
| 383 |
type 'a type1 = [ `T1 of 'a ] |
| 384 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 385 |
|
| 386 |
type 'a type2 = |
| 387 |
[ 'a type1 |
| 388 |
| `T2 |
| 389 |
] |
| 390 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 391 |
|
| 392 |
type 'a type3 = |
| 393 |
[ `T3 |
| 394 |
| 'a type1 |
| 395 |
] |
| 396 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 397 |
|
| 398 |
type 'a type4 = |
| 399 |
[ 'a type2 |
| 400 |
| `T4 |
| 401 |
| 'a type3 |
| 402 |
] |
| 403 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 404 |
|
| 405 |
type 'a id = 'a [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 406 |
|
| 407 |
type ('a, 'b) u = [ `u of 'a * 'b ] |
| 408 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 409 |
|
| 410 |
type t = [ | (int, int) u ] |
| 411 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 412 |
end |
| 413 |
|
| 414 |
module Equal = struct |
| 415 |
let%test _ = [%compare.equal: int list] [ 7; 8; 9 ] [ 7; 8; 9 ] |
| 416 |
let%test _ = not ([%compare.equal: int list] [ 7; 8 ] [ 7; 8; 9 ]) |
| 417 |
|
| 418 |
let%test _ = |
| 419 |
match [%compare: int * int] (1, 2) (1, 3) with |
| 420 |
| -1 -> true |
| 421 |
| _ -> false |
| 422 |
;; |
| 423 |
|
| 424 |
let%test _ = |
| 425 |
match [%compare: int * int] (1, 3) (1, 2) with |
| 426 |
| 1 -> true |
| 427 |
| _ -> false |
| 428 |
;; |
| 429 |
|
| 430 |
let%test _ = [%compare.equal: string option] None None |
| 431 |
let%test _ = not ([%compare.equal: string option] (Some "foo") None) |
| 432 |
let%test _ = [%compare.equal: string] "hello" "hello" |
| 433 |
let%test _ = not ([%compare.equal: string] "hello" "goodbye") |
| 434 |
end |
| 435 |
|
| 436 |
module Equal_local = struct |
| 437 |
let%test _ = [%compare_local.equal: int list] [ 7; 8; 9 ] [ 7; 8; 9 ] |
| 438 |
let%test _ = not ([%compare_local.equal: int list] [ 7; 8 ] [ 7; 8; 9 ]) |
| 439 |
|
| 440 |
let%test _ = |
| 441 |
match [%compare_local: int * int] (1, 2) (1, 3) with |
| 442 |
| -1 -> true |
| 443 |
| _ -> false |
| 444 |
;; |
| 445 |
|
| 446 |
let%test _ = |
| 447 |
match [%compare_local: int * int] (1, 3) (1, 2) with |
| 448 |
| 1 -> true |
| 449 |
| _ -> false |
| 450 |
;; |
| 451 |
|
| 452 |
let%test _ = [%compare_local.equal: string option] None None |
| 453 |
let%test _ = not ([%compare_local.equal: string option] (Some "foo") None) |
| 454 |
let%test _ = [%compare_local.equal: string] "hello" "hello" |
| 455 |
let%test _ = not ([%compare_local.equal: string] "hello" "goodbye") |
| 456 |
end |
| 457 |
|
| 458 |
module Type_extensions : sig |
| 459 |
|
| 460 |
|
| 461 |
module type S = sig |
| 462 |
type 'a t |
| 463 |
|
| 464 |
val compare : [%compare: _ t] |
| 465 |
val equal : [%compare.equal: _ t] |
| 466 |
val compare__local : [%compare_local: _ t] |
| 467 |
val equal__local : [%compare_local.equal: _ t] |
| 468 |
end |
| 469 |
end = struct |
| 470 |
module type S = sig |
| 471 |
type 'a t |
| 472 |
|
| 473 |
val compare : 'a t -> 'a t -> int |
| 474 |
val equal : 'a t -> 'a t -> bool |
| 475 |
val compare__local : 'a t -> 'a t -> int |
| 476 |
val equal__local : 'a t -> 'a t -> bool |
| 477 |
end |
| 478 |
end |
| 479 |
|
| 480 |
module Ignoring_field = struct |
| 481 |
type t = |
| 482 |
{ a : int [@ignore] |
| 483 |
; b : int |
| 484 |
; c : int |
| 485 |
} |
| 486 |
[@@deriving_inline compare, equal] |
| 487 |
|
| 488 |
let _ = fun (_ : t) -> () |
| 489 |
|
| 490 |
let compare = |
| 491 |
(fun a__1375_ b__1376_ -> |
| 492 |
if Stdlib.( == ) a__1375_ b__1376_ |
| 493 |
then 0 |
| 494 |
else ( |
| 495 |
match compare_int a__1375_.b b__1376_.b with |
| 496 |
| 0 -> compare_int a__1375_.c b__1376_.c |
| 497 |
| n -> n) |
| 498 |
: t -> t -> int) |
| 499 |
;; |
| 500 |
|
| 501 |
let _ = compare |
| 502 |
|
| 503 |
let equal = |
| 504 |
(fun a__1377_ b__1378_ -> |
| 505 |
if Stdlib.( == ) a__1377_ b__1378_ |
| 506 |
then true |
| 507 |
else |
| 508 |
Stdlib.( && ) (equal_int a__1377_.b b__1378_.b) (equal_int a__1377_.c b__1378_.c) |
| 509 |
: t -> t -> bool) |
| 510 |
;; |
| 511 |
|
| 512 |
let _ = equal |
| 513 |
|
| 514 |
[@@@deriving.end] |
| 515 |
|
| 516 |
let equal = [%compare.equal: t] |
| 517 |
end |
| 518 |
|
| 519 |
module Ignoring_inline = struct |
| 520 |
type t = int * int * int |
| 521 |
|
| 522 |
let compare = [%compare: _ * (int[@ignore]) * int] |
| 523 |
let _ = compare |
| 524 |
let equal = [%compare.equal: t] |
| 525 |
let%test _ = equal (0, 1, 2) (9, 1, 2) |
| 526 |
let%test _ = equal (0, 1, 2) (0, 9, 2) |
| 527 |
let%test _ = not (equal (0, 1, 2) (0, 1, 9)) |
| 528 |
end |
| 529 |
|
| 530 |
module Ignoring = struct |
| 531 |
type t = { a : (int[@ignore]) * string } [@@deriving_inline compare, equal] |
| 532 |
|
| 533 |
let _ = fun (_ : t) -> () |
| 534 |
|
| 535 |
let compare = |
| 536 |
(fun a__1395_ b__1396_ -> |
| 537 |
if Stdlib.( == ) a__1395_ b__1396_ |
| 538 |
then 0 |
| 539 |
else ( |
| 540 |
let t__1397_, t__1398_ = a__1395_.a in |
| 541 |
let t__1399_, t__1400_ = b__1396_.a in |
| 542 |
match |
| 543 |
let (_ : _) = t__1397_ |
| 544 |
and (_ : _) = t__1399_ in |
| 545 |
0 |
| 546 |
with |
| 547 |
| 0 -> compare_string t__1398_ t__1400_ |
| 548 |
| n -> n) |
| 549 |
: t -> t -> int) |
| 550 |
;; |
| 551 |
|
| 552 |
let _ = compare |
| 553 |
|
| 554 |
let equal = |
| 555 |
(fun a__1401_ b__1402_ -> |
| 556 |
if Stdlib.( == ) a__1401_ b__1402_ |
| 557 |
then true |
| 558 |
else ( |
| 559 |
let t__1403_, t__1404_ = a__1401_.a in |
| 560 |
let t__1405_, t__1406_ = b__1402_.a in |
| 561 |
Stdlib.( && ) |
| 562 |
(let (_ : _) = t__1403_ |
| 563 |
and (_ : _) = t__1405_ in |
| 564 |
true) |
| 565 |
(equal_string t__1404_ t__1406_)) |
| 566 |
: t -> t -> bool) |
| 567 |
;; |
| 568 |
|
| 569 |
let _ = equal |
| 570 |
|
| 571 |
[@@@deriving.end] |
| 572 |
|
| 573 |
let%test _ = equal { a = 1, "hi" } { a = 2, "hi" } |
| 574 |
let%test _ = not (equal { a = 1, "hi" } { a = 1, "ho" }) |
| 575 |
end |
| 576 |
|
| 577 |
module Ignoring_with_type = struct |
| 578 |
type t = |
| 579 |
{ a : int |
| 580 |
; b : (int[@compare.ignore]) |
| 581 |
} |
| 582 |
[@@deriving_inline compare] |
| 583 |
|
| 584 |
let _ = fun (_ : t) -> () |
| 585 |
|
| 586 |
let compare = |
| 587 |
(fun a__1407_ b__1408_ -> |
| 588 |
if Stdlib.( == ) a__1407_ b__1408_ |
| 589 |
then 0 |
| 590 |
else ( |
| 591 |
match compare_int a__1407_.a b__1408_.a with |
| 592 |
| 0 -> |
| 593 |
let (_ : _) = a__1407_.b |
| 594 |
and (_ : _) = b__1408_.b in |
| 595 |
0 |
| 596 |
| n -> n) |
| 597 |
: t -> t -> int) |
| 598 |
;; |
| 599 |
|
| 600 |
let _ = compare |
| 601 |
|
| 602 |
[@@@deriving.end] |
| 603 |
end |
| 604 |
|
| 605 |
module Enum_optim = struct |
| 606 |
type t = |
| 607 |
| A |
| 608 |
| B |
| 609 |
| C |
| 610 |
[@@deriving_inline compare, equal] |
| 611 |
|
| 612 |
let _ = fun (_ : t) -> () |
| 613 |
let compare = (Stdlib.compare : t -> t -> int) |
| 614 |
let _ = compare |
| 615 |
let equal = (Stdlib.( = ) : t -> t -> bool) |
| 616 |
let _ = equal |
| 617 |
|
| 618 |
[@@@deriving.end] |
| 619 |
end |
| 620 |
|
| 621 |
module Lazy_behavior = struct |
| 622 |
|
| 623 |
type a = unit |
| 624 |
|
| 625 |
let equal_a () () = assert false |
| 626 |
let equal_a__local () () = assert false |
| 627 |
let compare_a () () = assert false |
| 628 |
let compare_a__local () () = assert false |
| 629 |
|
| 630 |
type b = int * a [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 631 |
|
| 632 |
let%test _ = not (equal_b (0, ()) (1, ())) |
| 633 |
let%test _ = Base.Poly.( < ) (compare_b (0, ()) (1, ())) 0 |
| 634 |
end |
| 635 |
|
| 636 |
module Not_ieee_compliant = struct |
| 637 |
type t = float [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 638 |
|
| 639 |
let%test _ = [%equal: t] nan nan |
| 640 |
let%test _ = Base.Poly.( = ) ([%compare: t] nan nan) 0 |
| 641 |
end |
| 642 |
|
| 643 |
module Wildcard : sig |
| 644 |
type _ transparent = int [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 645 |
type _ opaque [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 646 |
end = struct |
| 647 |
type _ transparent = int [@@deriving compare, equal, compare ~localize, equal ~localize] |
| 648 |
|
| 649 |
let%test _ = [%equal: string transparent] 1 1 |
| 650 |
let%test _ = not ([%equal: string transparent] 1 2) |
| 651 |
let%test _ = Base.Poly.( < ) ([%compare: string transparent] 1 2) 0 |
| 652 |
let%test _ = Base.Poly.( = ) ([%compare: string transparent] 1 1) 0 |
| 653 |
let%test _ = Base.Poly.( > ) ([%compare: string transparent] 2 1) 0 |
| 654 |
|
| 655 |
type 'a opaque = 'a option |
| 656 |
[@@deriving compare, equal, compare ~localize, equal ~localize] |
| 657 |
|
| 658 |
let%test _ = [%equal: int opaque] (Some 1) (Some 1) |
| 659 |
let%test _ = not ([%equal: int opaque] None (Some 1)) |
| 660 |
let%test _ = not ([%equal: int opaque] (Some 1) (Some 2)) |
| 661 |
let%test _ = Base.Poly.( < ) ([%compare: int opaque] None (Some 1)) 0 |
| 662 |
let%test _ = Base.Poly.( = ) ([%compare: int opaque] (Some 1) (Some 1)) 0 |
| 663 |
let%test _ = Base.Poly.( > ) ([%compare: int opaque] (Some 2) (Some 1)) 0 |
| 664 |
end |
| 665 |
|
| 666 |
module Local_with_aliased_comparisons : sig |
| 667 |
type t = |
| 668 |
| Int of int |
| 669 |
| Add of t * t |
| 670 |
| Sub of t * t |
| 671 |
[@@deriving_inline compare ~localize, equal ~localize] |
| 672 |
|
| 673 |
include sig |
| 674 |
[@@@ocaml.warning "-32"] |
| 675 |
|
| 676 |
include Ppx_compare_lib.Comparable.S with type t := t |
| 677 |
include Ppx_compare_lib.Comparable.S_local with type t := t |
| 678 |
include Ppx_compare_lib.Equal.S with type t := t |
| 679 |
include Ppx_compare_lib.Equal.S_local with type t := t |
| 680 |
end |
| 681 |
[@@ocaml.doc "@inline"] |
| 682 |
|
| 683 |
[@@@end] |
| 684 |
end = struct |
| 685 |
type t = |
| 686 |
| Int of int |
| 687 |
| Add of t * t |
| 688 |
| Sub of t * t |
| 689 |
[@@deriving_inline compare ~localize, equal ~localize] |
| 690 |
|
| 691 |
let _ = fun (_ : t) -> () |
| 692 |
|
| 693 |
let rec compare__local = |
| 694 |
(fun a__1541_ b__1542_ -> |
| 695 |
if Stdlib.( == ) a__1541_ b__1542_ |
| 696 |
then 0 |
| 697 |
else ( |
| 698 |
match a__1541_, b__1542_ with |
| 699 |
| Int _a__1543_, Int _b__1544_ -> compare_int__local _a__1543_ _b__1544_ |
| 700 |
| Int _, _ -> -1 |
| 701 |
| _, Int _ -> 1 |
| 702 |
| Add (_a__1545_, _a__1547_), Add (_b__1546_, _b__1548_) -> |
| 703 |
(match compare__local _a__1545_ _b__1546_ with |
| 704 |
| 0 -> compare__local _a__1547_ _b__1548_ |
| 705 |
| n -> n) |
| 706 |
| Add _, _ -> -1 |
| 707 |
| _, Add _ -> 1 |
| 708 |
| Sub (_a__1549_, _a__1551_), Sub (_b__1550_, _b__1552_) -> |
| 709 |
(match compare__local _a__1549_ _b__1550_ with |
| 710 |
| 0 -> compare__local _a__1551_ _b__1552_ |
| 711 |
| n -> n)) |
| 712 |
: t -> t -> int) |
| 713 |
;; |
| 714 |
|
| 715 |
let _ = compare__local |
| 716 |
let compare = (fun a b -> compare__local a b : t -> t -> int) |
| 717 |
let _ = compare |
| 718 |
|
| 719 |
let rec equal__local = |
| 720 |
(fun a__1553_ b__1554_ -> |
| 721 |
if Stdlib.( == ) a__1553_ b__1554_ |
| 722 |
then true |
| 723 |
else ( |
| 724 |
match a__1553_, b__1554_ with |
| 725 |
| Int _a__1555_, Int _b__1556_ -> equal_int__local _a__1555_ _b__1556_ |
| 726 |
| Int _, _ -> false |
| 727 |
| _, Int _ -> false |
| 728 |
| Add (_a__1557_, _a__1559_), Add (_b__1558_, _b__1560_) -> |
| 729 |
Stdlib.( && ) |
| 730 |
(equal__local _a__1557_ _b__1558_) |
| 731 |
(equal__local _a__1559_ _b__1560_) |
| 732 |
| Add _, _ -> false |
| 733 |
| _, Add _ -> false |
| 734 |
| Sub (_a__1561_, _a__1563_), Sub (_b__1562_, _b__1564_) -> |
| 735 |
Stdlib.( && ) |
| 736 |
(equal__local _a__1561_ _b__1562_) |
| 737 |
(equal__local _a__1563_ _b__1564_)) |
| 738 |
: t -> t -> bool) |
| 739 |
;; |
| 740 |
|
| 741 |
let _ = equal__local |
| 742 |
let equal = (fun a b -> equal__local a b : t -> t -> bool) |
| 743 |
let _ = equal |
| 744 |
|
| 745 |
[@@@end] |
| 746 |
end |