Skip to content

Commit

Permalink
Support OCaml 4.08 (missing List.equal)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lupus committed Mar 8, 2024
1 parent 733f4c9 commit 86dd22c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compilerlib/pb_raw_option.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let option_name_part_equal a b =
| Extension_name a, Extension_name b -> String.equal a b
| _ -> false

let option_name_equal = List.equal option_name_part_equal
let option_name_equal = Pb_util.List.equal option_name_part_equal
let empty = []
let add option_set option_name value = (option_name, value) :: option_set

Expand Down
6 changes: 6 additions & 0 deletions src/compilerlib/pb_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ module List = struct
(match f x with
| Some _ as r -> r
| None -> find_map f tl)

let rec equal eq l1 l2 =
match l1, l2 with
| [], [] -> true
| [], _ :: _ | _ :: _, [] -> false
| a1 :: l1, a2 :: l2 -> eq a1 a2 && equal eq l1 l2
end

module Int_map = Map.Make (struct
Expand Down
12 changes: 12 additions & 0 deletions src/compilerlib/pb_util.mli
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ module List : sig

val find_opt : ('a -> bool) -> 'a list -> 'a option
val find_map : ('a -> 'b option) -> 'a list -> 'b option

val equal : ('a -> 'a -> bool) -> 'a list -> 'a list -> bool
(** [equal eq [a1; ...; an] [b1; ..; bm]] holds when
the two input lists have the same length, and for each
pair of elements [ai], [bi] at the same position we have
[eq ai bi].
Note: the [eq] function may be called even if the
lists have different length. If you know your equality
function is costly, you may want to check {!compare_lengths}
first.
*)
end

module Str_map : Map.S with type key = string
Expand Down

0 comments on commit 86dd22c

Please sign in to comment.