-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add Pp.verbatimf #18
add Pp.verbatimf #18
Conversation
Follow the same naming scheme as existing functions textf and paragraphf. Signed-off-by: Mathieu Barbin <[email protected]>
Thanks for the PR! Looks like I got the type of There I also added a This seems like a sensible addition to me. |
Hi @Alizter, Thank you for looking into it ! 😄
It's been a while since I looked at these highly polymorphic format parametrized types... 🧐 My impression is that the added Do you believe this type is not inferred from the fact that |
Signed-off-by: Mathieu Barbin <[email protected]>
@mbarbin It will enforce the type of the |
In fact, I don't think this is this the case. The returned type of the full invocation is the last parameter of the format4, and it is correctly inferred as being I just looked again here. I think the added annotation doesn't add any safety in that it only coerces the parameter with the same type as already inferred. |
@mbarbin Yes, you're totally correct. I think what is needed is to add that type to the mli, then it would be able to enforce the correct type, but that has the side effect of polluting the mli which isn't desirable. |
Ah, I think I now understand what you mean. OK, I believe having the correct type in the mli is enough to get a compile error on the previous implementation, so it should be all you need (and not need the added annotation in the ml). |
I think a better way to enforce the correct type is just to add some simple tests like you've done. |
I agree yes. It's too easy to get it wrong otherwise! Thanks for the follow through and for #19 |
CHANGES: - Prepare release (ocaml-dune/pp#21, @mbarbin) - Upgrade to `ocamlformat.0.26.2`. - Fmt the code - Add CI badge to README - Upgrade GitHub workflow actions dependencies (checkout@v4, setup-ocaml@v3) - Add more validation steps in CI - Add `ocamlformat` as dev-setup dependency - Add `Pp.verbatimf`. (ocaml-dune/pp#18, @mbarbin) - Add `Pp.paragraph` and `Pp.paragraphf` (ocaml-dune/pp#19, @Alizter) - Remove `of_fmt` constructor. (ocaml-dune/pp#17, @Alizter)
Follow the same naming scheme as existing functions textf and paragraphf.
This function is meant to allow simplifying occurrences of the pattern
Pp.verbatim (Printf.sprintf ...)
.As a motivating example, you may refer to this file (although it is taken from a toy project).
Thank you for pp!