ppx_import
ppx_import copied to clipboard
Drop 'private' on demand?
Hi,
I'd like to redeclare many of my currently abstract types as private so their contents are visible to ocamldebug. If ppx_import allowed me to change an imported type's visibility from private to public on demand, I could do that with a lot less redundant typing. Do you think such a feature could be added (maybe by resurrecting the commit prior to #8 and exposing it via another directive such as %import_dropping_private)? Or maybe there already is a way to achieve that with the current version of ppx_import which I am not aware of? thanks, Sebastian
I'm confused. Can you show me a minimal example with your current code, and with your desired code? Also, ppx_import adds a manifest type so I think if ppx_import did what you want it'd not typecheck.
sure, let's say I have a module named Test
, where Test.mli
contains the following:
type t = private A of int | B (* not declared abstract as that would render ocamldebug relatively useless *) (* ... function declarations follow *)
Within Test.ml
, I'd now have to completely replicate the declaration of t
, up to the keyword 'private':
type t = A of int | B (* ... etc ... *)
That way, the internals of Test.t
are (IMHO) reasonably well-isolated from the outside world while still allowing for convenient introspection via ocamldebug. What I'd like to do is to replace the type definition within Test.ml
by type t = [%import: Test.t]
. As that import directive now no longer drops the private
keyword, however, t
is isolated even from Test.ml
itself, which prevents me from doing anything useful with it.
I had expected this to be possible, as it seems to be pretty close to what test_self_import does?
Ohh you mean importing from own mli! There should just be a branch that if you import from your own mli then private
should be dropped. Because there is no way to construct this type otherwise.
that would be awesome :)
I have no plans to implement this but you are welcome to submit a PR. Such a change should be fairly trivial.