diff --git a/src/lib_utils/PP.ml b/src/lib_utils/PP.ml index 1665d4a57..a32854c6f 100644 --- a/src/lib_utils/PP.ml +++ b/src/lib_utils/PP.ml @@ -18,6 +18,14 @@ let ne_list_sep value separator ppf (hd, tl) = let prepend s f ppf a = fprintf ppf "%s%a" s f a +let option = fun f ppf opt -> + match opt with + | Some x -> fprintf ppf "Some(%a)" f x + | None -> fprintf ppf "None" + +let map = fun f pp ppf x -> + pp ppf (f x) + let pair_sep value sep ppf (a, b) = fprintf ppf "%a %s %a" value a sep value b let smap_sep value sep ppf m = let module SMap = X_map.String in diff --git a/src/lib_utils/dictionary.ml b/src/lib_utils/dictionary.ml index 76fc8cb14..130c01af8 100644 --- a/src/lib_utils/dictionary.ml +++ b/src/lib_utils/dictionary.ml @@ -27,7 +27,7 @@ module Assoc : DICTIONARY = struct let set ?equal lst a b = let equal : 'a -> 'a -> bool = - Option.unopt + X_option.unopt ~default:(=) equal in let rec aux acc = function @@ -39,7 +39,7 @@ module Assoc : DICTIONARY = struct let del ?equal lst a = let equal : 'a -> 'a -> bool = - Option.unopt + X_option.unopt ~default:(=) equal in let rec aux acc = function diff --git a/src/lib_utils/option.ml b/src/lib_utils/option.ml deleted file mode 100644 index 4ee7859ff..000000000 --- a/src/lib_utils/option.ml +++ /dev/null @@ -1,3 +0,0 @@ -let unopt ~default = function - | None -> default - | Some x -> x diff --git a/src/lib_utils/tezos_utils.ml b/src/lib_utils/tezos_utils.ml index 3c7086378..38bf94f97 100644 --- a/src/lib_utils/tezos_utils.ml +++ b/src/lib_utils/tezos_utils.ml @@ -14,7 +14,7 @@ module PP_helpers = PP module Location = Location module List = X_list -module Option = Tezos_base.TzPervasives.Option +module Option = X_option module Cast = Cast module Tuple = Tuple module Map = X_map diff --git a/src/lib_utils/trace.ml b/src/lib_utils/trace.ml index f39658fca..ca54980f0 100644 --- a/src/lib_utils/trace.ml +++ b/src/lib_utils/trace.ml @@ -334,13 +334,13 @@ module Assert = struct let assert_equal_int ?msg expected actual = let msg = let default = Format.asprintf "Not equal int : expected %d, got %d" expected actual in - Option.unopt ~default msg in + X_option.unopt ~default msg in assert_equal ~msg expected actual let assert_equal_bool ?msg expected actual = let msg = let default = Format.asprintf "Not equal bool : expected %b, got %b" expected actual in - Option.unopt ~default msg in + X_option.unopt ~default msg in assert_equal ~msg expected actual let assert_none ?(msg="not a none") opt = match opt with diff --git a/src/lib_utils/tree.ml b/src/lib_utils/tree.ml index d76ec20ab..7b4c5886a 100644 --- a/src/lib_utils/tree.ml +++ b/src/lib_utils/tree.ml @@ -108,4 +108,14 @@ module Append = struct match t with | Empty -> None | Full t' -> assoc_opt' t' k + + let rec pp' : _ -> _ -> 'a t' -> unit = fun f ppf t' -> + match t' with + | Leaf x -> Format.fprintf ppf "%a" f x + | Node {a;b} -> Format.fprintf ppf "N(%a , %a)" (pp' f) a (pp' f) b + + let pp : _ -> _ -> 'a t -> unit = fun f ppf t -> + match t with + | Empty -> Format.fprintf ppf "[]" + | Full x -> Format.fprintf ppf "[%a]" (pp' f) x end diff --git a/src/lib_utils/x_option.ml b/src/lib_utils/x_option.ml new file mode 100644 index 000000000..2063463db --- /dev/null +++ b/src/lib_utils/x_option.ml @@ -0,0 +1,6 @@ +include Tezos_stdlib.Option + +let lr (a , b) = match (a , b) with + | Some x , _ -> Some (`Left x) + | None , Some x -> Some (`Right x) + | _ -> None