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

Xavier Clerc xavier.clerc at inria.fr
Wed Jan 30 11:00:34 GMT 2013



----- Mail original -----
> On 01/30/2013 10:27 AM, Xavier Clerc wrote:
> > Personally, I think that declaring attributes with their fields
> > and types is pretty useful.
> 
> I don't see how to do that without introducing a lot of complexity in
> the system.  Do you mean we should run the OCaml type-checker on
> attribute arguments before they are processed?  Or that we should
> restrict attribute arguments to be pure constant data (records,
> constructors, literals)?  This seems overly restrictive.  It make
> sense
> to allow full expressions within attributes (e.g. some uses of
> type-conv
> requires to annotate types with functions), and I don't see how to
> type-check that.

Java made the choice to restrict to constants.
This is indeed restrictive, but make sure that it is easy to check
whether an annotation is correct, and also to store it for future
use.



> > This protects the user from some
> > typos and other obvious errors, and avoid boiler-plate code in
> > the attribute processors.
> 
> I don't expect a lot of tedious boiler-plate code in the processors
> (OCaml is not so bad at pattern matching, after all) if they need to
> check some "constraints" on their arguments (not really
> type-checking,
> but rather checking simple things like the fact that they come with a
> string literal argument).

Well, there are two things: the boiler-plate code (maybe not such
a big problem in OCaml, as you point out), and the fact that if the
constraints are always checked by the same piece of code, error messages
presented to the end-user will be uniform.


Xavier Clerc


More information about the wg-camlp4 mailing list