diff --git a/lib/caqti_common_priv.ml b/lib/caqti_common_priv.ml index c415053b..22ca8090 100644 --- a/lib/caqti_common_priv.ml +++ b/lib/caqti_common_priv.ml @@ -48,6 +48,12 @@ module List = struct let rec iter_r f = function | [] -> Ok () | x :: xs -> (match f x with Ok () -> iter_r f xs | Error _ as r -> r) + + let rec equal f xs ys = + (match xs, ys with + | [], [] -> true + | x :: xs', y :: ys' -> f x y && equal f xs' ys' + | [], _ :: _ | _ :: _, [] -> false) end let finally cleanup thunk = diff --git a/lib/caqti_common_priv.mli b/lib/caqti_common_priv.mli index 0007181e..cab4da1b 100644 --- a/lib/caqti_common_priv.mli +++ b/lib/caqti_common_priv.mli @@ -42,6 +42,7 @@ module List : sig val fold : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b val fold_r : ('a -> 'b -> ('b, 'e) result) -> 'a list -> 'b -> ('b, 'e) result val iter_r : ('a -> (unit, 'e) result) -> 'a list -> (unit, 'e) result + val equal : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool end val finally : (unit -> unit) -> (unit -> 'a) -> 'a diff --git a/lib/caqti_query.ml b/lib/caqti_query.ml index b3db9308..fe951d61 100644 --- a/lib/caqti_query.ml +++ b/lib/caqti_query.ml @@ -14,6 +14,8 @@ * along with this library. If not, see . *) +open Caqti_common_priv + type t = | L of string | Q of string @@ -45,13 +47,7 @@ let rec equal t1 t2 = | L s1, L s2 -> String.equal s1 s2 | Q s1, Q s2 -> String.equal s1 s2 | P i1, P i2 -> Int.equal i1 i2 - | S l1, S l2 -> - let rec list_equal a b = - match (a, b) with - | ([], []) -> true - | (a::x, b::y) -> equal a b && (list_equal x y) - | _ -> false in - list_equal l1 l2 + | S ts1, S ts2 -> List.equal equal ts1 ts2 | L _, _ -> false | Q _, _ -> false | P _, _ -> false