Created
June 15, 2023 14:25
-
-
Save Octachron/6d503f5edaad633c4736c222d25e4a61 to your computer and use it in GitHub Desktop.
Hlist for format printing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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