From: Siraaj Khandkar Date: Tue, 11 Sep 2018 16:34:07 +0000 (-0400) Subject: Add map helper to build from list of pairs X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=be22952d3228b62e546756299a0f9a127ae64921;p=tiger.ml.git Add map helper to build from list of pairs --- 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