[wg-camlp4] Pending issues

Alain Frisch alain.frisch at lexifi.com
Wed Feb 13 13:12:52 GMT 2013


On 2/12/2013 9:12 PM, Pierre Chambart wrote:
> I would also prefer to
> restrict that kind of annotation to a small subset of the expression
> language avoiding as much as possible duplication.

Just to be clear, do you propose to restrict attributes in general, or 
only those which will be reflected in runtime types?   There are several 
cases where one really wants to be able to use general expressions as 
attributes, such as the example given by Yaron:

          type t =
            { a : int with default(2), sexp_drop_if(fun x -> x = 2);
            } with sexp

One could imagine restricting attributes to structured constants, and 
one would have to write the expression as a string literal to be parsed 
explicitly by the ppx rewriter.  Two arguments against doing so:

   - You loose editor support (admittedly, attributes are likely to be 
short enough that we don't care).

   - You need to be more careful about the order in which ppx rewriters 
are applied. Imagine a variant of the example above:

    type t =
      { a : int with default(2), sexp_drop_if("fun x -> x = DEFAULT");
      } with sexp

  where DEFAULT is to be expanded by another ppx rewriter.  Then you 
need to ensure that the macro expander is run after "sexp", not before. 
  And one could build other examples where one really needs the macro 
expander to apply to the attribute's content before it is processed 
(which works only if the attribute content is parsed).


Alain


More information about the wg-camlp4 mailing list