[wg-camlp4] PG'OCaml and syntax proliferation

Dario Teixeira darioteixeira at yahoo.com
Mon Jan 28 15:10:59 GMT 2013


Hi,


Another syntax extension to consider is PG'OCaml's.  Though it seems like
it can easily be adapted to the ppx system, it does raise an issue which I
think ought to be discussed.

Here's how code making use of embedded SQL in PG'OCaml currently looks like:
(the dbh parameter is the database handle)

  let fetch_users dbh =
        PGSQL(dbh) "select id, name from users"

This is syntactally incorrect, of course.  Therefore, any adaptation to the
ppx system will necessarily be backwards-incompatible with existing code
(not a big problem for me personally, but others may disagree).  As for
the new syntax, several possibilities exist.  A straightforward one would
be to lowercase the "PGSQL" token; embedded SQL statements would thus take
the form of fake function calls:

  let fetch_users dbh =
        pgsql(dbh) "select id, name from users"

Another possiblity would be for the SQL statements to be arguments to a fake
variant type constructor:

  let fetch_users dbh =
        PGSQL (dbh, "select id, name from users")

I could go on.  Anyway, regardless of choice, one issue comes to mind.
Presently, code using the PG'OCaml syntax extension is conspicuous by its
syntactic incorrectness.  Therefore, someone unfamiliar with PG'OCaml who
happened to be looking at code using the syntax extension would immediately
suspect something camlp4ish was going on.  With ppx, this signaling would
go away.  This could make code harder to read if several syntax extensions
are simultaneously used, particularly if syntax extensions become more
popular because ppx makes it so much easier to write them.

One solution is for the community to adopt conventions that make syntax
extensions stand out to the naked eye (syntax highlighters in Vim or Emacs
could also take advantage of these conventions).  For example: the fake variant
constructor could be instead a fake PV constructor ending in "'" (prime).
It should not be hard for editors to highlight this code in a special way:

  let fetch_users dbh =
        `PGSQL' (dbh, "select id, name from users")

What do you think?

Best regards,
Dario Teixeira



More information about the wg-camlp4 mailing list