From 63d105d54b6343235935d81937b207881c5145fe Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Tue, 29 Nov 2016 16:31:37 -0800 Subject: [PATCH] ppx_compare IList Reviewed By: cristianoc Differential Revision: D4232365 fbshipit-source-id: 853f6df --- infer/src/base/IList.ml | 19 +++++-------------- infer/src/base/IList.mli | 5 ++--- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/infer/src/base/IList.ml b/infer/src/base/IList.ml index 32c110f69..8f28efb72 100644 --- a/infer/src/base/IList.ml +++ b/infer/src/base/IList.ml @@ -7,6 +7,11 @@ * of patent rights can be found in the PATENTS file in the same directory. *) +type 'a t = 'a list [@@deriving compare] + +let equal cmp l1 l2 = + compare cmp l1 l2 = 0 + let exists = List.exists let filter = List.filter let find = List.find @@ -83,20 +88,6 @@ let rec drop_first n = function let drop_last n list = rev (drop_first n (rev list)) -(** Generic comparison of lists given a compare function for the elements of the list *) -let rec compare cmp l1 l2 = - match l1, l2 with - | [],[] -> 0 - | [], _ -> - 1 - | _, [] -> 1 - | x1:: l1', x2:: l2' -> - let n = cmp x1 x2 in - if n <> 0 then n else compare cmp l1' l2' - -(** Generic equality of lists given a compare function for the elements of the list *) -let equal cmp l1 l2 = - compare cmp l1 l2 = 0 - (** Returns (reverse input_list) *) let rec rev_with_acc acc = function | [] -> acc diff --git a/infer/src/base/IList.mli b/infer/src/base/IList.mli index 71574492b..cb37354db 100644 --- a/infer/src/base/IList.mli +++ b/infer/src/base/IList.mli @@ -7,11 +7,10 @@ * of patent rights can be found in the PATENTS file in the same directory. *) -(** Generic comparison of lists given a compare function for the elements of the list *) -val compare : ('a -> 'b -> int) -> 'a list -> 'b list -> int +type 'a t = 'a list [@@deriving compare] (** Generic equality of lists given a compare function for the elements of the list *) -val equal : ('a -> 'b -> int) -> 'a list -> 'b list -> bool +val equal : ('a -> 'a -> int) -> 'a list -> 'a list -> bool (** tail-recursive variant of List.append *) val append : 'a list -> 'a list -> 'a list