Hi, and welcome !
You can’t “detect a type” as types are erased during the compilation and do not exist at runtime.
You can however remain more polymorphic by leaving the job of printing the 'a
payload in your 'a rle
values to some function passed as argument. Something like:
let print_rle_list pp rles =
Format.printf
"@[<1>%a@]@.\n"
Format.(pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ";@ ")
(pp_rle pp)
)
rles
Also if you want your pretty-printer to remain composable, you should not use @.
or \n
in it, as that will reset the formatting engine. If you find yourself writing a lot of printers by hand, you could also look into the fmt
to make that less painful.