[wg-camlp4] Improvements to the OCaml Parsetree

Alain Frisch alain.frisch at lexifi.com
Tue Apr 16 16:50:37 BST 2013


On 01/28/2013 04:43 PM, Romain Bardou wrote:
> About assert false as a special node: I think it should stay like this.
>
> It may add a case to treat, but the treatment will usually be trivial.
> If it is not, then it will probably be an instance of the assert case,
> in which case you can just call the assert case with <<false>> as an
> argument. Else it means that you have a very different treatment for
> false and in this case, you’re glad that they are separate.
>
> Moreover, this case really is a special case as it is typed differently.
> I think it is better if the parse tree reflects this, so that the
> programmer is conscious of this when transforming assertions.

I've given it some thought, and I'm no longer convinced by the argument. 
  I can see two concrete reasons for treating "assert false" in the 
type-checker:

  - -ppx rewriters could very well produce an assert node with a "false" 
expression and it would behave differently from an "assert false" in the 
source code.  This would be quite puzzling, and round-tripping with the 
concrete syntax becomes impossible.

  - It is not clear what to do with "assert (false[@foo])".


I don't think we should insist to keep the Parsetree as close as 
possible to the concrete syntax if this adds extra complexity (e.g. 
keeping parentheses and other syntactic details does not seem very 
useful), but this seems to be a case where there is no strong reason to 
not do it and it will actually simplify the Parsetree to do so.

So unless someone strongly objects to it, I'll get rid of 
Pexp_assertfalse and add support for the special case in the type-checker.


Alain


More information about the wg-camlp4 mailing list