[wg-camlp4] Against the use of syntactically-valid OCaml code for syntax extension purposes
Leo White
lpw25 at cam.ac.uk
Tue Jan 29 11:15:34 GMT 2013
I would just like to say that I mostly agree with Gabriel. Where possible I
think we should try to choose syntaxes that are obviously syntax
extensions.
For example, I don't think that:
let rec expr =
<:parser <
If; x = expr; Then; y = expr; Else; z = expr -> "if"
| Let; Ident x; Equal; x = expr; In; y = expr -> "let" >>
is really worse than
let rec expr =
parser
[< 'If; x = expr; 'Then; y = expr; 'Else; z = expr >] -> "if"
| [< 'Let; 'Ident x; 'Equal; x = expr; 'In; y = expr >] -> "let"
and it makes it very clear that it is using an extension.
In some cases it seems sensible to use an obviously wrong syntax (e.g.
!"asdf"), but in general I think we should try to use new syntax for
extensions.
In particular I think that the following forms can cover many cases:
* Camlp4-style quotations: <:foo < arg >>
* Some kind of quotation that looks like a type constructor and is quietly
ignored by the main compiler. I personally like the syntax "%foo" and
"%bar(arg)".
* Type-conv style annotations: type t = int with foo, bar(arg)
* Allowing let and maybe some other keywords to be suffixed by some symbols
(e.g. let*)
* Allowing top-level style directives in ml files (e.g. "#ifdef ;;").
More information about the wg-camlp4
mailing list