[wg-camlp4] A new branch to experiment with extension points

Alain Frisch alain.frisch at lexifi.com
Mon Mar 4 14:32:02 GMT 2013

On 03/04/2013 02:52 PM, Gabriel Scherer wrote:
 > For once, all delimiters in the
 > OCaml syntax so far are symmetric ([, {, (, but also [< and {<),

This is not true, for instance, for ocamldoc comments (I know they are 
not part of the OCaml syntax!), and personally I'm not sure to see the 
benefit of making the syntax heavier just to keep symmetry.

> Could the
> two syntaxes share a single delimiter prefix, for example [: and [:: ?
 > ...
 > I think we really need a prefix syntax.

I don't have a strong opinion on syntax, and I agree with the need for a 
prefix syntax (another example:  ocamldoc section header, as a 
prefix-attribute on an "include").

Leo seems to be a lot more comfortable than me with hacking the concrete 
syntax, so I'll let him comment on the possibilities.

> 2. I'm unsure about generalization of the "with" syntax to other
> syntactic cases. In expression context, "with" is very much associated
> to pattern matching, and in particular there is syntactic contention
> around a potential "let try ... = ... with ... in" construct. Using
> "with" in local module open introduces avenue for confusion.

I was thinking about using the "with" syntax only for 
structure/signature item-like components (only that we want to attach 
them to individual component in case of multi-component declarations), 
and probably exclude the expression-as-a-structure-item case.

But it's true that the following:

open M with foo
include S with foo

can be misleading (this is not a with constraint on module type S).

(Before someone question the need for attributes on such items: yes, I 
think it can be useful.  For instance to guide, an attribute on an 
include statement in an interface could instruct ocamldoc whether it 
should inline the corresponding module type or keep it as a reference. 
For open: an attribute could control whether ocamldoc should use the 
opened module to shorten names in the generated doc.)

What about:

  ... [@id expr]    (* attribute on expression, pattern, type, module 
type, module expr *)

  [^id expr] ...    (* same, prefix syntax *)

  ... [@@id expr]   (* attribute on str/sig item-like components *)

  [#id expr]        (* extension as an expression, etc. *)


More information about the wg-camlp4 mailing list