Ppx_deriving: opaque for visitors but not for show

I use ppx_deriving both for deriving printers (show) and visitors (https://gitlab.inria.fr/fpottier/visitors). Both derivers recognize the [@opaque] annotation to ignore some branches of the type.

I would like to declare some branches opaque for visitors without making them opaque for show (these branches have abstract types for which a printer is provided, but no visitors).

Currently, I use a [@printer] annotation that I put before the [@opaque] annotation to specify the printer explicitly, but I would hope for a solution that does not require to repeat the names of the types.

type t = A of (data [@printer pp_data] [@opaque])
      [@@deriving show, visitors { variety = "iter" }]

Thank you, OCaml community!

Hi Thierry,

ppx_deriving should support namespacing of attributes. You can try using [@visitors.opaque] to pass opaque to visitors only.

2 Likes

Oh, thank you! I missed this namespacing of attributes when I read the documentation!

1 Like