| 1 |
module List = struct |
| 2 |
include Stdlib.ListLabels |
| 3 |
|
| 4 |
let rec equal ~eq xs ys = |
| 5 |
match xs, ys with |
| 6 |
| [], [] -> true |
| 7 |
| x :: xs, y :: ys -> eq x y && equal ~eq xs ys |
| 8 |
| _, _ -> false |
| 9 |
;; |
| 10 |
|
| 11 |
let rec compare a b ~cmp:f : int = |
| 12 |
match a, b with |
| 13 |
| [], [] -> 0 |
| 14 |
| [], _ :: _ -> -1 |
| 15 |
| _ :: _, [] -> 1 |
| 16 |
| x :: a, y :: b -> |
| 17 |
(match f x y with |
| 18 |
| 0 -> compare a b ~cmp:f |
| 19 |
| ne -> ne) |
| 20 |
;; |
| 21 |
end |
| 22 |
|
| 23 |
module Poly = struct |
| 24 |
let equal = ( = ) |
| 25 |
let compare = compare |
| 26 |
end |
| 27 |
|
| 28 |
module Phys_equal = struct |
| 29 |
let equal = ( == ) |
| 30 |
end |
| 31 |
|
| 32 |
let ( = ) = Int.equal |
| 33 |
let ( == ) = [ `Use_phys_equal ] |
| 34 |
let ( < ) x y = Int.compare x y = -1 |
| 35 |
let ( > ) x y = Int.compare x y = 1 |
| 36 |
let min (x : int) y = min x y |
| 37 |
let max (x : int) y = max x y |
| 38 |
let compare = Int.compare |
| 39 |
|
| 40 |
module Option = struct |
| 41 |
include Option |
| 42 |
|
| 43 |
module Unboxed : sig |
| 44 |
type 'a t |
| 45 |
|
| 46 |
val none : 'a t |
| 47 |
val some : 'a -> 'a t |
| 48 |
val is_none : 'a t -> bool |
| 49 |
val is_some : 'a t -> bool |
| 50 |
val value_exn : 'a t -> 'a |
| 51 |
val to_option : 'a t -> 'a option |
| 52 |
val iter : 'a t -> f:('a -> unit) -> unit |
| 53 |
end = struct |
| 54 |
type 'a t = Obj.t |
| 55 |
|
| 56 |
let some x = Obj.repr x |
| 57 |
let none = Obj.repr (Sys.opaque_identity (-1)) |
| 58 |
let phys_equal = Stdlib.( == ) |
| 59 |
let is_none t = phys_equal t none |
| 60 |
let is_some t = not (phys_equal t none) |
| 61 |
|
| 62 |
let value_exn t = |
| 63 |
if is_none t then invalid_arg "Option.Unboxed.value_exn called on None"; |
| 64 |
Obj.obj t |
| 65 |
;; |
| 66 |
|
| 67 |
let to_option t = if is_none t then None else Some (value_exn t) |
| 68 |
let iter t ~f = if is_none t then () else f (value_exn t) |
| 69 |
end |
| 70 |
end |
| 71 |
|
| 72 |
module Int = struct |
| 73 |
let[@warning "-32"] hash (x : int) = Hashtbl.hash x |
| 74 |
|
| 75 |
include Stdlib.Int |
| 76 |
end |