From d39dd1fee28765822a84b854113b4db9f59a094e Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Thu, 9 Jul 2020 07:44:59 -0700 Subject: [PATCH] [sledge] Add: Array hash and sexp functions Summary: For `[@deriving hash, sexp]` convenience. Reviewed By: jvillard Differential Revision: D22401037 fbshipit-source-id: f7538ac1f --- sledge/nonstdlib/NS.ml | 8 ++++++++ sledge/nonstdlib/NS.mli | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/sledge/nonstdlib/NS.ml b/sledge/nonstdlib/NS.ml index 6af127af3..078f4afb6 100644 --- a/sledge/nonstdlib/NS.ml +++ b/sledge/nonstdlib/NS.ml @@ -82,6 +82,13 @@ module List = List module Array = struct include Core.Array + let hash_fold_t hash_fold_elt s a = + Hash.Builtin.hash_fold_array_frozen hash_fold_elt s a + + module Import = struct + type 'a array = 'a t [@@deriving compare, equal, hash, sexp] + end + let pp sep pp_elt fs a = List.pp sep pp_elt fs (to_list a) let fold_map_inplace a ~init ~f = @@ -95,6 +102,7 @@ module Array = struct !s end +include Array.Import module IArray = IArray include IArray.Import module Set = Set diff --git a/sledge/nonstdlib/NS.mli b/sledge/nonstdlib/NS.mli index 28c9cbcfa..58af30089 100644 --- a/sledge/nonstdlib/NS.mli +++ b/sledge/nonstdlib/NS.mli @@ -79,12 +79,19 @@ module List = List module Array : sig include module type of Array + type 'a t = 'a Array.t [@@deriving compare, equal, hash, sexp] + + module Import : sig + type 'a array = 'a t [@@deriving compare, equal, hash, sexp] + end + val pp : (unit, unit) fmt -> 'a pp -> 'a array pp val fold_map_inplace : 'a array -> init:'s -> f:('s -> 'a -> 's * 'a) -> 's end +include module type of Array.Import module IArray = IArray include module type of IArray.Import module Set = Set