[wg-camlp4] Improvements to the OCaml Parsetree

Alain Frisch alain.frisch at lexifi.com
Mon Jan 28 15:25:43 GMT 2013


Dear all,

Another useful topic for discussion related to -ppx are improvements to 
the OCaml Parsetree itself.  Of course, since the Parsetree is "going 
public" with -ppx, it make sense to improve it before too much code 
depend on it.

Let me list of few points I have in mind:

  - Get rid of some tuples / n-ary constructors in favor of proper 
record types (self-documented, more future proof).  Similarly, prefer 
explicit constructors to "bool" flags (although if we use more records, 
this is less of a problem).

  - Get rid of weird encodings in favor of more explicit representation. 
For instance, Pexp_when: guard expressions should be explicitly put next 
to patterns (or maybe allowed within the pattern algebra with some 
type-error if they are not at the toplevel).  Also, I'm not sure about 
the special "Pexp_assertfalse" node.  Do you have another examples?

  - Be more liberal about where Ptyp_poly must/might appear (the 
type-checker currently expect some dummy Ptyp_poly wrapper in some 
places, and the parser know that).

  - Avoid doing too much desugaring in the parser.  For instance, we 
should probably distinguish between "let open M in e" and "M.(e)" in the 
Parsetree.  Where to stop exactly, I'm not sure.  For instance, I don't 
have a clear opinion on whether record field punning should be handled 
purely in the parser or reflected in the Parsetree.  What do people here 
think?

  - This needs to be discussed, but what about remove those Ptyp_, 
Pexp_, ...., prefixes everywhere?  And similarly for record fields 
(ptype_, ...). Now that we have type-based disambiguation of 
constructors/labels, we don't really need those prefixes and they 
increase the verbosity of AST rewriters.  Some experimentation is 
needed, though.


Don't hesitate to comment on those points and add more!


Alain


More information about the wg-camlp4 mailing list