[wg-camlp4] On domain-specific foreign syntaxes

Anil Madhavapeddy anil at recoil.org
Thu Jan 31 13:22:08 GMT 2013


On 31 Jan 2013, at 13:11, Alain Frisch <alain.frisch at lexifi.com> wrote:

> When non-programmers have to write some HTML code, this code rarely ends up in OCaml source code.  Usually, it stays in its own HTML file, which is then processed (statically or dynamically) by the (OCaml) code.
> 
> When fragments of JSON/XML/etc are created programatically, this is often done "piece by piece", with very small fragments involving a high density of anti-quotations.  The benefits of using the foreign syntax here are not clear to me.

This does match my experience with pa_css, pa_json, pa_xml while building the Mirage website.  For example:

https://github.com/mirage/mirage-www/blob/master/src/style.ml#L71
https://github.com/mirage/mirage-www/blob/master/src/wiki.ml

are both either flat templates, or fairly dense with antiquotations.  It is quite nice that I can paste in some HTML code and get type errors from the XMLM parser.

More recently, I've been using Martin Jambon's new tools that perform external code generation instead, and it's quite a pleasant experience.  For example, the Github bindings use his ATD tool which auto-generates the parsing code into separate OCaml modules:

https://github.com/avsm/ocaml-github/blob/master/lib/github.atd

With ATD, you retain type safety, but lose other benefits of embedding code (most notably, using modules to control the visibility of the generated types).  The build system integration also took some thought, although this is ocamlbuild's fault.

I can't immediately think of a good case where programmatic fragments of JSON/XML really need the current quotation/antiquotation mechanism.  If it simplifies editor support, I'd be happy enough to lose this functionality.

-anil


More information about the wg-camlp4 mailing list