-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add note about nested libraries #3111
Conversation
As explained in ocaml#3102 Signed-off-by: Yawar Amin <[email protected]>
@@ -327,6 +327,12 @@ OCaml/Reason modules only consume modules from the directory where the | |||
stanza appear. In order to declare a multi-directory library, you need | |||
to use the :ref:`include_subdirs` stanza. | |||
|
|||
Note also that a nested library in a project is not automatically namespaced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term "nested library" does not exist in the documentation, so I'm not sure what you're referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm referring to libraries in subdirectories of libraries. Is there a more standard terminology used for that? If so I can easily change to that.
under its parent library. E.g. if you have a public library ``foo`` which nests | ||
another public library ``bar``, it will not be exposed as ``Foo.Bar`` outside | ||
the project, but as ``Bar``. Take care to give unique names to nested libraries | ||
to avoid conflicts. E.g., ``foo__Bar``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double underscores in names are a (private) artifact of how dune builds modules, I don't think it's a good idea to reuse this kind of names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree, double underscores are a widespread convention in the OCaml community which dune adopted. Dune doesn't 'own' the double underscores naming convention.
[EDIT: to clarify, double underscores are certainly the only relatively unambiguous way to disambiguate toplevel module names in OCaml. Dune can't claim exclusive ownership of that :-)]
From the point of view of Dune, double underscores are an implementation detail. In particular, they are not mentioned in the documentation. If a future version of OCaml allows to hide them, Dune will hide them. |
Hi @diml , what concretely would happen to such modules e.g. What about if I alias the nested module like |
Well, if you explicitly call your module or library However, if you write: (library
(name foo)
(modules bar)) the fact that dune chooses to compile |
I may have misunderstood something. In which case this PR may be moot. Let me try to verify :-)
Then does Dune still make I realize this is something I can check for myself, and I will when I get home tonight. I suppose I just wanted to capture it somewhere :-) |
@diml so my suggestion above doesn't work. Dune seems to not recognize
That is exactly what I am suggesting in this PR. Key line of the added doc:
|
There's an important point with wrapped libraries: users are never supposed to refer in their code to modules with double underscores in them. It's not possible to completely hide that today, but a user is supposed to never see double underscores. This is why the suggestion to mention |
I agree with @emillon, we should definitely not encourage users to use BTW, note that the two following setups are exactly the same from the point of view of Dune: Setup 1:
Setup 2:
In other terms, where you decide to put your libraries doesn't matter to Dune. A library is simply the collection of the modules present in the same directory as the
In practice yes, but users of Dune shouldn't reason at the level of cm files or make assumption about how they are organised. What you should know is that:
|
Lots to digest in both your replies :-) Let me try to clarify a couple of things. @emillon I agree that it's less than optimal :-) A better solution would have been that Dune did not expose nested libraries as top-level-accessible modules. I am simply proposing a layout (which is working quite well for me and I thought that others would want the same benefit) that will mitigate that to an extent.
That is totally reasonable but I am proposing that a library should be named
It's strange, I literally last night tried this setup and got the following error:
I've uploaded an example repo here, would appreciate if you could let me know what I'm doing wrong!
Agreed, I was just talking about .cmi files as a shorthand way of asking, 'Will this nested library's module be visible at the top-level i.e. will it conflict with other top-level modules'.
This all makes sense; my question is specifically about the other case, that is about a library |
To clarify the situation, it seems to me that what you're after is a way to reflect the nesting of directories as a nesting of modules, so that If it is, the codename for that feature is |
@emillon indeed, that's exactly what I want :-) in the absence of built-in support, I'm using nested libraries which seems to be the recommended approach to doing that. However, I also want there to be an awareness that nested library names are globally namespaced, because people may be using them unaware of that and publishing potentially any number of clashing top-level modules. I hope that makes sense :-) |
That makes a lot more sense to me too 😄 If you really want to this nesting now, calling the sub-library From the point of view of Dune, the best we can recommend is to wait for
Unless you use |
As explained in #3102