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

Leo White lpw25 at cam.ac.uk
Sat Feb 2 19:25:00 GMT 2013


>   (@deriving ["sexp"; "json"])
>   type t = F of int | G of s
>    and s = H of (t * t)
>
>or
>
>    (@perform)
>       (x <-- m;
>        y <-- n;
>        return (x y))
>
>In order for this to be valid code, 'deriving' and 'perform' should
>resolve to functions of appropriate types:
>
>    val deriving : string list -> Parsetree.structure_item ->
>Parsetree.structure_item
>
>    val perform : Parsetree.expression -> Parsetree.expression
>

I have a broader proposal that is along these lines, which is intended to 
be the second part of my earlier blog post. There are in general some 
difficulties with just calling functions during parsing, but I think the 
general idea of declared extensions is the right way to do things.

The reason I haven't mentioned this proposal yet, is that it is a more long 
term proposal. We can easily implement the changes needed to support ppx 
before the next OCaml release. Whereas full support for declared extensions 
will require more time, and probably a lot more debate before it can be 
included.

Since moving an extension from ppx to some kind of declared mechanism would 
require only minimal work, I see no harm in promoting ppx in the 
short/medium term, while also developing a more complete solution.

In particular I think that the extension/template syntaxes ( "(: lid 
expr)", "{: lid { string }}", etc.) that have been discussed so far will be 
a very good match for a declaration based mechanism. It is also another 
argument for forcing extensions to have names.

I will try to put my own proposals in that blog post early next week.


More information about the wg-camlp4 mailing list