Skip to content

Instantly share code, notes, and snippets.

@Octachron
Created June 15, 2023 14:25
Show Gist options
  • Save Octachron/6d503f5edaad633c4736c222d25e4a61 to your computer and use it in GitHub Desktop.
Save Octachron/6d503f5edaad633c4736c222d25e4a61 to your computer and use it in GitHub Desktop.
Hlist for format printing
module L = struct
type 'args t =
| [] : unit t
| (::): 'a * 'b t -> ('a -> 'b) t
end
let rec print_list: type args result.
Format.formatter -> args -> args L.t -> unit =
fun ppf print -> function
| [] -> ()
| arg :: rest -> print_list ppf (print arg) rest
let fprintf ppf fmt args =
print_list ppf (Format.fprintf ppf fmt) args
let fatal_error fmt args =
let ppf = Format.err_formatter in
fprintf ppf fmt args;
fprintf ppf "@." [];
failwith "Unrecoverable error"
let test = if false then fatal_error "%s" ["foo";"bar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment