[wg-camlp4] Against the use of syntactically-valid OCaml code for syntax extension purposes

Leo White lpw25 at cam.ac.uk
Wed Jan 30 11:43:51 GMT 2013


On Jan 30 2013, Alain Frisch wrote:

>On 01/30/2013 10:40 AM, Leo White wrote:
>>> I'd rather write it:
>>>
>>>   foo bar ((@marker) e)
>>
>> I would prefer it to have its own syntax, because I would like to
>> encourage its use. I think that it is easier to read than a normal
>> attribute because it clearly declares its scope
>
>I don't see the point: the scope of an attribute must be quite explicit 
>as well (but maybe the current syntax is not clear enough).

The point is that there are fundamentally two kinds of extension.

The first kind are things which themselves represent 
expressions/patterns/... . For example:

<:html < <body> ... </body> >> 

{:PGSQL dbh "select id, name from users"}

and the second kind are those that act on an existing 
expression/pattern/... . For example:

val foo: int -> int  {%depreciated}

In the first case, the syntax inside the brackets may look like OCaml but 
it will be translated. In the second kind the expression that the attribute 
is attached to *is* OCaml code. It may be acted on in some way (e.g. placed 
inside some boilerplate) but it fundamentally is OCaml code.

Failure to translate the first kind must raise an error. Failure to 
translate the second kind does not necessarily require an error.

I think that these differences is enough to justify separate (but similar) 
syntaxes. I don't think that everyone using the first kind of extension 
should have to use a syntax more suited to the second kind.




More information about the wg-camlp4 mailing list