In F # printf there is a %A format specifier that allows you to pass any type of F #, and it will be evaluated and printed.
As an example:
type Result<'a> = | Failure | Success of 'a printf "%A" (Success "hello") // prints out 'Success "hello"'
Where, obviously, Result<'a> not a built-in type.
I can declare a similar type in OCaml, but for Printf.printf there is no equivalent qualifier, instead I would have to implement my own function string_of_result and use the %s qualifier in the format string. Moreover, since this is a polymorphic type, I would have to create an indirect function that can handle an instance of any type of 'a .
My question is: why is OCaml missing this convenient specifier? Is it because there is no incentive to implement it? Is this due to the fact that some of them do not have a scammer under the hood, which is only in F #?
f # ocaml
asafc
source share