[wg-camlp4] Request for feedback

Leo White lpw25 at cam.ac.uk
Thu Mar 14 11:00:02 GMT 2013


> If people see examples written "let%lwt", they will probably do the same, don't you think?   "%" does not seem very
> common in OCaml code; I don't think people already have "bad habits" about it.  And if people insist to write "let %
> lwt", it will be because they believe it somehow better.
>
> I'm not very fond of "let.lwt".  The dot symbol has already so many different uses in OCaml...  At least "%" is quite
> rare and will thus be clearly noticed as an extension.
>
>> Another posibility would be
>>
>>    let .% lwt x = ...
>
> Do you believe it is worth making the syntax more heavy only to discourage (and not even prevent) people from
> potentially writing code with a style we don't like?
>

To be honest I am (cautiously) ok with "let%lwt x = ...". 

>> It does seems like we're going from having a single extension syntax to
>> having many extension syntaxes. I can see the benefit of "let % lwt"
>> since that will probably be a common extension point (the same goes for
>> "match % bit") but is there much to be gained from the other possible
>> keyword extensions.
>
> function%ext and try%ext are also probably useful.

I'm much less sure about these other syntaxes. I think that

    [%bit match foo with
        bit-pattern -> ...
      | other-bit-pattern -> ...
    ]

makes it much more obvious that we are abusing the OCaml syntax within
an extension, which is important. It is also not much heavier than:

    match%bit foot with
      bit-pattern -> ...
    | other-bit-pattern -> ...

The same goes for function%ext and try%ext.

Note that for "let" the trade-off is potentially much worse:

[%lwt let x = .... in
  [%lwt let y = ... in
    [%lwt let z = ... in
       ...
    ]
  ]
]

vs.

let%lwt x = ... in
let%lwt y = ... in
let%lwt z = ... in
  ...

So while I think it is worth it for let, I'm much less sure about the
other constructs. I also think that it will be difficult to persuade the
OCaml developers to allow "KWD % id" all over the place.

> And I can imagine examples where {%ext x1=e1; ...; xn=en} would be useful as well (see the "pre-polyrecord" example).

[%ext x1=e1; ...; xn=en] would already be valid. Also, this might get in
the way of my proposed short quotation extension form: {%id { .... }}.

Which reminds me, at the very least, we must implement a {x{ ... }x}
quoting construct for quotation extensions.

>> While "let % lwt" may be alright, I do think that
>>
>> ( % id expr )
>>
>> is a bad idea. It looks too much like a prefix operator. Also, having a
>> two character delimiter that isn't a single token is different from
>> every other two character delimiter in the langauge. It also means that
>> you can't use precedence to resolve conflicts in the parser. Is there
>> any real benefit in using (%id expr) instead of [%id expr]?
>
> The benefit I can see is the uniformity with other forms of expressions:
>
>    KW%id ...
>
> where KW is the opening keyword/symbol (here "(") and ... the rest of the construction starting with KW.

I don't think there is any uniformity here, people do not think of
keywords and delimiters as equivalent, and do not expect them to behave
the same. They do expect all delimiters to behave the same, which is why
"( % id expr )" really should not be allowed.


More information about the wg-camlp4 mailing list