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

Leo White lpw25 at cam.ac.uk
Thu Feb 21 18:39:37 GMT 2013


>What would be the justification for hierarchical names?  It seems that a 
>flat qualifier is enough to support the two goals you mention (making 
>components with the same filename coexist, and grouping them with a 
>common name).  In practice, we will have a namespace per distributed 
>library (e.g. Core, Extlib, Xml-light, ...).  Restricting to flat 
>qualifiers might enable a simpler design.

Large libraries can also contain multiple components with the same name. 
For example, a library might provide both Foo.Aysc.IO and Foo.Lwt.IO.

I don't think having hierarchical namespaces really adds much additional 
complexity to the system.

More generally, almost all naming systems are hierarchical. It is a tried 
and tested way of organising things.

>Personally, I'm not even convinced of the need for supporting several 
>compilation units with the same filename.  Basically, we will encode 
>namespace information inside the .cmi instead of doing it in the 
>filename, forcing the compiler to open files only to discover they are 
>not in the correct namespace.  Is it really so tedious to use longer 
>filenames?  

Is it really so tedious for the compiler to look in multiple .cmi files 
until the right one is found?

Long filenames don't allow you to open or alias a namespace, they also 
don't allow you to change the namespaces that are open by default. All of 
which are useful features.

I also think that long filenames *are* tedious, if they weren't people 
would use them already. If you are using a large library, even with a good 
aliasing feature, you would end up writing:

  open Core_Std_Mutex as Mutex
  open Core_Std_Thread as Thread
  open Core_Std_Date as Date

at the beginning of all your files, instead of writing:

  open Core.Std

Regards,

Leo



More information about the Platform mailing list