[wg-camlp4] Changes to the parsetree

Alain Frisch alain.frisch at lexifi.com
Wed Apr 10 15:25:12 BST 2013


On 04/10/2013 03:34 PM, Gabriel Scherer wrote:
> I think that having additional constructors in core_type that are
> semantically meaningless (the variance annotations) will not help
> third-party extension writers either. What are the reasons for having
> the whole core_type in place where type variables are expected?

I can see the following reasons:

  - It's actually not only type variables.  Since the introduction of 
GADT, you can also use "_" as a type parameter (only for type 
declarations, not classes).  This is currently encoded as a "string loc 
option", which is not very self-describing.

  - Using core_type gives attributes for free. Otherwise, we need to 
complexify to Parsetree definition and the parser to allow attributes 
explicitly.

  - If we represent variance information +/- as constructors of 
core_type, it further simplifies the definition in the Parsetree (from 
"(variance * string loc option) list" to "core_type list"), thus making 
it sometimes simpler to match or create fragments of ASTs.

  - I see it generally as a good thing that fragments with identical 
syntax are represented in the same way in the Parsetree.  Of course, 
this is far from being the case because there are lots of duplication 
between the various syntactic categories, but since a "'a" as a type 
parameter will also be used with the same syntax "'a" as a type 
expression close to it (in the same type declaration), one could argue 
that they should be of the same "kind".

But I'm not pushing too much in this direction.  Leo made the request, 
so I'd let him comment!

Alain


More information about the wg-camlp4 mailing list