[wg-camlp4] My uses of syntax extension

Alain Frisch alain at frisch.fr
Mon Jan 28 14:33:48 GMT 2013


On 01/28/2013 02:06 PM, Török Edwin wrote:
> Backward compatibility would be appreciated, especially for something as simple as IFDEF.
 >...
> Thinking about backward compatibility again perhaps there should be more transformation phases:

Backward compatibility is an important topic, since the goal of this 
working group is to propose a migration plan.

My personal view is that we should not complexify our "target" (-ppx) 
only to support backward compatibility.  Clearly, -ppx will require some 
user-visible changes, since it is no longer an option to change the 
concrete syntax.  To take a concrete example, what should a project like 
js_of_ocaml do, once they have a fully functional -ppx version?
An option could be to keep maintaining their camlp4 extension in 
parallel, but extend it to support for the syntax chosen for the -ppx 
version.  The only benefit of it is that users stuck with older versions 
of ocaml can still move smoothly to the new syntax, so as to be ready to 
get rid of camlp4 at some point.  Other users don't need that: they can 
rewrite their project progressively (e.g. module per module) using both 
the camlp4 syntax extension and the -ppx rewriter, and then stop using 
camlp4 when everything has been rewritten.  Is it worth the effort to 
adapt the camlp4 extension to match the new syntax?  It's probably up to 
each project maintainer to decide (considering that supporting several 
versions of camlp4 is also quite challenging).  Who is really stuck with 
old versions of ocaml (and still wanting and able to use new versions of 
packages)?

> Also it'd be nice to have:
>   -ppt Typedtree -> Typedtree for type-level transformations

I don't believe this is a viable option.  Producing Typedtree without 
breaking invariants of the type system (and the type soundness) is 
extremely challenging.  I'd be more comfortable with supporting a 
"Typedtree -> Parsetree" pass, where you'd only need to be able to use 
information from the typedtree so as to produce fragments of code which 
are then type-checked again.  You don't need to fully understand 
everything in the Typedtree to do that, and the type-checker acts as a 
safety net.

OCamlPro worked on a project called "OCaml Templates" doing exactly 
that, but I don't know the status of this project.  (Someone from 
OCamlPro to comment?)


Alain




More information about the wg-camlp4 mailing list