[wg-camlp4] Against the use of syntactically-valid OCaml code for syntax extension purposes

Xavier Clerc xavier.clerc at inria.fr
Wed Jan 30 09:27:52 GMT 2013


----- Mail original -----
> On 01/30/2013 07:31 AM, Gabriel Scherer wrote:
> > My understanding is that this is precisely what type-conv does:
> > annotate the type declaration itself, rather than the type
> > expression
> > or the whole phrase.
> 
> I agree it make sense to allow attaching attributes to various
> syntactic
> constructions, including those which are not "algebra", and type
> declaration are a good candidate for that.  Note that when I proposed
> attributes, I wrote:
> 
> > I propose to start discussing the addition of attributes to most
> > syntactic categories (expressions, type expressions, patterns,
> > type declarations, module expressions, structure/signature items,
> > etc).
> 
> I'm not sure we need to allow attributes on specific parts of
> expression
> kinds (e.g. annotate the "for" itself, or each binding in a "let").
> I'm
> not fundamentally opposed to it, but it will add a lot of complexity
> to
> the Parsetree with no obvious benefit.  This probably needs to be
> discussed on a case-by-case basis.

I have several questions related to attributes, regardless of their
actual syntax. The questions stem from my limited knowledge of their
Java equivalent.

1- should attributes be declared before use ? and if so, should the
contents of attributes be typed? To be concrete, in Java, you are
allowed to annotate something with "@MyAnnot(a=1, b="two")" iff
"MyAnnot" has been declared with fields "a" (of type "int") and "b"
(of type "string").

2- if you declare attributes before use, would it be desirable to
be able to select which syntactic constructs they can annotate ?
To be concrete, you might decide that a "@profile" attribute can
be used with expressions, but not with types.

3- should annotations be stored (e. g. in cmi/cmo/cmx files) in
order for an attribute processor to be able to access attributes
of other modules ?


Personally, I think that declaring attributes with their fields
and types is pretty useful. This protects the user from some
typos and other obvious errors, and avoid boiler-plate code in
the attribute processors.

Do list readers have strong opinions on these questions ?


Xavier Clerc


More information about the wg-camlp4 mailing list