From 8678923ca2cf0534e2f43413ef5306e555aa57c2 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Thu, 1 Jul 2021 03:30:25 -0700 Subject: [PATCH] [sledge] Add List.Assoc support for deriving compare, equal, sexp_of Reviewed By: ngorogiannis Differential Revision: D29441157 fbshipit-source-id: cc90ad68b --- sledge/nonstdlib/list.ml | 3 +++ sledge/nonstdlib/list.mli | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sledge/nonstdlib/list.ml b/sledge/nonstdlib/list.ml index e236b797e..30e7378b2 100644 --- a/sledge/nonstdlib/list.ml +++ b/sledge/nonstdlib/list.ml @@ -112,6 +112,9 @@ let pp_diff ~cmp ?pre ?suf sep pp_elt fs (xs, ys) = module Assoc = struct include Assoc + let compare (type k v) compare_k compare_v = [%compare: (k * v) list] + let equal (type k v) equal_k equal_v = [%equal: (k * v) list] + let sexp_of_t sexp_of_k sexp_of_v = [%sexp_of: (k * v) list] let mem elt seq ~eq = mem ~eq elt seq end diff --git a/sledge/nonstdlib/list.mli b/sledge/nonstdlib/list.mli index 24d12046a..947b2a13e 100644 --- a/sledge/nonstdlib/list.mli +++ b/sledge/nonstdlib/list.mli @@ -103,7 +103,9 @@ val symmetric_diff : cmp:('a -> 'a -> int) -> 'a t -> 'a t -> ('a, 'a) Either.t t module Assoc : sig - include module type of Assoc + type ('k, 'v) t = ('k * 'v) list [@@deriving compare, equal, sexp_of] + + include module type of Assoc with type ('k, 'v) t := ('k, 'v) t val mem : 'a -> ('a, _) t -> eq:('a -> 'a -> bool) -> bool end