[ocaml-platform] on the need and design of OCaml namespaces

Xavier Clerc xavier.clerc at inria.fr
Mon Feb 25 21:40:30 GMT 2013


----- Mail original -----
> On 2/25/2013 8:13 PM, Xavier Clerc wrote:
> > This is no what I mean.
> > Packs and namespaces serve two different purposes.
> > It just happens that the lack of namespace forced
> > people (including me) to use packs as namespaces.
> 
> Why forced?

"forced" was maybe too strong... :-)


> I haven't seen a lot of libraries relying on -pack
> instead
> of using unique enough module names (but it's true that I don't use a
> lot of third-party libraries).  Using the library name as a common
> prefix for all its modules (and maybe having a module whose name is
> the
> library name itself in case of libraries with a clear notion of "main
> public module") seems a quite good solution to me and a better one
> than
> -pack.

Well, it is not a bad solution, but packing allows to open the library
at once. Not to say that this is a must have but I find it convenient
in practice.


>  Maybe this solution is not so good for libraries whose goal
> is
> to act as a "standard library" (such as Core), because the intention
> is
> to create the impression that the library is actually part of the
> language (I don't have the impression to use a library when I write
> String.length or List.map, contrary to when I write Xmlm.make_input);
> so
> I understand why Jane Street is reluctant to have Core_list.map
> everywhere in their code.  But would it really be a problem to have
> the
> users write "open Kaputt_abbreviations" instead of "open
> Kaputt.Abbreviations", or Bolt_logger.log instead of Bolt.Logger.log?

For those libraries, with few modules, it could be a decent solution.
But for Barista (with 50+ modules), it is nice to be able to open the
library as mentioned above. Moreover, library code is also made lighter
by packing: in another Bolt module, "Logger.log" is sufficient (there
is no ambiguity) while your solution would imply to write "Bolt_logger.log".

It just occurs to me that packing obviously allows (or enforces)
"closed" namespaces: no one can add a module to the packed module.
Is the ability to "close" a namespace something considered useful?

Xavier


More information about the Platform mailing list