ppx_import icon indicating copy to clipboard operation
ppx_import copied to clipboard

Drop 'private' on demand?

Open sebastiansturm opened this issue 7 years ago • 5 comments

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

sebastiansturm avatar May 26 '17 09:05 sebastiansturm

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.

whitequark avatar May 26 '17 09:05 whitequark

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?

sebastiansturm avatar May 26 '17 12:05 sebastiansturm

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.

whitequark avatar May 26 '17 13:05 whitequark

that would be awesome :)

sebastiansturm avatar May 26 '17 14:05 sebastiansturm

I have no plans to implement this but you are welcome to submit a PR. Such a change should be fairly trivial.

whitequark avatar May 26 '17 15:05 whitequark