utils.ml 472 Bytes
Newer Older
Pietro Abate's avatar
Pietro Abate committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
let string_of_formatter pp t =
  Format.fprintf Format.str_formatter "%a" pp t;
  Format.flush_str_formatter ()

let pp_list ?(delim=("[","]")) ?(sep=",") f ppf l =
  let rec aux ppf = function
    |[] -> Format.fprintf ppf ""
    |[h] -> Format.fprintf ppf "%a" f h
    |h::t -> Format.fprintf ppf "%a%s%a" f h sep aux t
  in
  match l with
    |[] -> Format.fprintf ppf "%s%s" (fst delim) (snd delim)
    |_ -> Format.fprintf ppf "%s%a%s" (fst delim) aux l (snd delim)