-
Notifications
You must be signed in to change notification settings - Fork 462
Description
Desired Behavior
Printing Dyn.Char with Dyn.pp currently outputs the char without the quotes, thus this is not valid OCaml syntax.
A lot of the ways dyn expressions are printed in the existing code is to use a syntax that ressembles the OCaml one (I haven't checked in exact details, but from what I can see, this really looks like you could copy/paste the code into a utop and this would work).
I would like to request to change the printing of the dyn char to include the quotes and make them valid OCaml literals, for consistency and re-enforce the idea that this module aims to print valid OCaml syntax. When used in expect tests, the familiar syntax of the expect test traces next to the code tested feels right and ergonomic.
Example
Here is the current:
let%expect_test "Dyn.char" =
let print_dyn dyn = Format.printf "%a@." Pp.to_fmt (Dyn.pp dyn) in
print_dyn (Dyn.char 'a');
[%expect {| a |}];
()
;;Here is what I would like to request instead:
let%expect_test "Dyn.char" =
let print_dyn dyn = Format.printf "%a@." Pp.to_fmt (Dyn.pp dyn) in
print_dyn (Dyn.char 'a');
- [%expect {| a |}];
+ [%expect {| 'a' |}];
()
;;Caveat: I haven't thought about more difficult cases where certain chars require special literal handling in the OCaml syntax.
Thank you!
Linking related tickets #12980