janestreet / ppx_custom_printf

Printf-style format-strings for user-defined string conversion
MIT License
23 stars 9 forks source link

"pp" transformer #1

Closed Drup closed 4 years ago

Drup commented 9 years ago

Would it be possible to have a way to use a pretty printing function instead of a to_string one ? It would ensure proper composition of pretty printing.

ghost commented 9 years ago

Currently custom formats (CamlinternalFormatBasics.Custom) have to return a string. When integrating the patch in the compiler we talked about generalizing them so they could be used with a Format.formatter but decided it wasn't worth the effort, at least initially. This is because the Format.formatter type would need to be defined before the CamlinternalFormatBasics.format6 type, so a few things would need to be moved around in the stdlib. If there is demand for it, it can probably be reconsidered.

Ccing @gasche and @bvaugon

Drup commented 9 years ago

I think it's worth the effort. to_string functions are not the way you should compose pretty printers (as they ignore both indentation and tag on the target).

v-gb commented 4 years ago

Realistically, we're not going to make this happen. First because the stdlib change looks like a non trivial amount of work, second because we use format very little, and finally because some of the usage of ppx_custom_printf is getting replaced by the string interpolation from ppx_string.

If someone made the stdlib support a Custom' constructor with a more general type, I think it should be easy to extend ppx_custom_printf to support this.

So I want to close this issue as non-actionable until someone changes the compiler. Any objection?

ghost commented 4 years ago

None from me