I’m trying to use (preprocess (pps ppx_deriving.show)) on a large type hierarchy. I added [@@deriving show] to the root type, but then I need to add it again to the next type and its dependencies. This feels quite daunting, especially when I encounter types defined in the standard library or in third-party dependencies.
Do you have any tips on how to approach this? I need to add it to over 100 types, and I’m not sure if this is a rabbit hole I want to go down.
In my case I have had at most 3 levels of type hierarchies where doing it manually on each type is feasible (as formally, I think, it should be done in each type). I have no experience with larger hierarchies and better fancy ways. But I am writing to tell you about ppx_import which can be useful for types in external libraries, in case you did not know, as you can use it in combination with ppx_deriving (in this link in FAQ there are some ideas of more advanced uses, maybe the odoc-ppx-deriving is also useful). Good luck.
But really, you can just import types in the order of their definition, and apply show to each in sequence. E.g. in pa_ppx/base/pp_parsetree.ORIG.ml at master · camlp5/pa_ppx · GitHub
you can see that there are a bunch of imports, in sequence, and for each, show is applied.
Note well: this is all done using the Camlp5-based pa_ppx PPX rewriters, not the ppxlib-based rewrites. But the same pattern should work: the pa_ppx-based rewriters are meant to be as close to work-alikes of the ppxlib-based rewrites as possible. So you shouldn’t have any problem adapting what I describe above.