From be22952d3228b62e546756299a0f9a127ae64921 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Tue, 11 Sep 2018 12:34:07 -0400 Subject: [PATCH] Add map helper to build from list of pairs --- compiler/src/lib/tiger/tiger_map_red_black.ml | 3 +++ compiler/src/lib/tiger/tiger_map_sig.ml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/compiler/src/lib/tiger/tiger_map_red_black.ml b/compiler/src/lib/tiger/tiger_map_red_black.ml index b339b52..30ba479 100644 --- a/compiler/src/lib/tiger/tiger_map_red_black.ml +++ b/compiler/src/lib/tiger/tiger_map_red_black.ml @@ -99,3 +99,6 @@ let to_dot t ~k_to_string = ) in "digraph G {" ^ dot_edges_and_nodes ^ "}" + +let of_list pairs = + List.fold_left pairs ~init:empty ~f:(fun t (k, v) -> set t ~k ~v) diff --git a/compiler/src/lib/tiger/tiger_map_sig.ml b/compiler/src/lib/tiger/tiger_map_sig.ml index 521b6cf..ed21d33 100644 --- a/compiler/src/lib/tiger/tiger_map_sig.ml +++ b/compiler/src/lib/tiger/tiger_map_sig.ml @@ -10,4 +10,6 @@ module type S = sig val member : ('k, 'v) t -> k:'k -> bool val to_dot : ('k, 'v) t -> k_to_string:('k -> string) -> string + + val of_list : ('k * 'v) list -> ('k, 'v) t end -- 2.20.1