utils.ml 509 Bytes
Newer Older
Pietro Abate's avatar
Pietro Abate committed
1
let string_of_formatter pp t =
2
  ignore (Format.flush_str_formatter ());
Pietro Abate's avatar
Pietro Abate committed
3 4 5 6
  Format.fprintf Format.str_formatter "%a" pp t;
  Format.flush_str_formatter ()

let pp_list ?(delim=("[","]")) ?(sep=",") f ppf l =
7 8 9 10 11 12
  let od, cd = delim in
  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
Pietro Abate's avatar
Pietro Abate committed
13 14
  in
  match l with
15 16
    [] -> Format.fprintf ppf "%s%s" od cd
  |_ -> Format.fprintf ppf "%s@ %a%s" od aux l cd