[wg-camlp4] Structured comments, shallow embeddings and deep quasiquotations

Leo White lpw25 at cam.ac.uk
Tue Feb 5 16:35:42 GMT 2013


>I don't see why this notion of quotation expander is linked to 
>namespaces.  The problem is not that the code for expanders is attached 
>to module, but simply that it this code needs to run during compilation, 
>and must thus have been compiled in an early stage of the build process 
>(and then linked statically/dynamically in the compiler or pre-processor 
>driver).  I don't think we need namespaces nor a new file extension to 
>do that.  Quotations expander are just regular OCaml code, with the full 
>expressive power of the language, and as any OCaml code to be compiled, 
>they need to be part of some module.  I don't see any problem here.

As I have tried to explain in the post, the problem is with combining code 
to be run at compile-time with code to be run at run-time. Trying to simply 
look in your current environment for an extension, as in Jeremy's proposal, 
means having just such a combination.

If the extension is part of a module then using it requires you to 
initialise that whole module at compile-time. This includes initialising 
(and so potentially executing) code in the module that is intended for 
run-time.

To prevent this from happening we can simply not allow extensions to be 
part of modules. However, we then have no means of referring to that 
extension. So in order to refer to these extensions we allow them to be 
members of namespaces.

>The OCaml code in .mlq files need to be compiled before any unit which 
>uses this expander, and it will be run somehow during the compilation of 
>that unit.  "User-land" code executed during compilation of another 
>piece of code look like staged compilation.

Only in the same way that a ppx extension is staged compilation.

By staged compilation I had assumed Gabriel had meant explicit in-language 
specification of what code is for compile-time and what code is for 
run-time. Similar to how a macro system based on MetaOCaml might look.

By not allowing extensions to be part of modules we avoid this issue, since 
only modules can be linked together to create a program.



More information about the wg-camlp4 mailing list