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

Anil Madhavapeddy anil at recoil.org
Mon Feb 25 14:15:54 GMT 2013


On 24 Feb 2013, at 19:26, Christophe TROESTLER <Christophe.Troestler at umons.ac.be> wrote:

> On Fri, 22 Feb 2013 11:41:10 +0000, Anil Madhavapeddy wrote:
>> 
>> There's one scenario which absolutely requires the ability to explicitly open a particular namespace: camlp4 code generation.
>> 
>> Right now, several camlp4 extensions break because they use modules from the standard Pervasives library, and have no way to explicitly state that.  If Core.Std is opened, then compilation fails.
>> 
>> The two workarounds are:
>> - hack the build system to pass -pp options to the camlp4 generator. Painful.
>> - have some facility to explicitly open 'Caml_std' or 'Core_std' locally, irrespective of the current module environment.
>> 
>> I believe namespaces addresses the latter workaround.
> 
> Camlp4 can insert some code to alias the standard modules needed by code generation at the beginning of the source files (not foolproof because a name needs to be generated but good enough in practice).  It would be better if that facility was provided by a Camlp4 module instead of needing to be redone by each extension.

That's an interesting idea.  The only hitch is that it's a little hard to do in one pass, as the code generation is called on the local AST fragment.

I think it would work if placed as a feature into type_conv itself, as the individual generators (e.g. sexp/orm) all register themselves with it quite early.  They could request global modules, which type_conv does in one pass (thus also avoiding duplicate requests for the original namespace).

CCing Markus Mottl to see what he thinks...

-anil



More information about the Platform mailing list