What's the state of -ppx syntax extensions for OCaml?
Asked Answered
S

1

7

There was a proposal from Alain Frisch of Lexifi over a year ago for an alternative to camlp4 for writing sytnax extensions making use of the -ppx flag added in OCaml 4.00. At that time he mentioned that there was still some work to be done (attributes, quotations, etc.) but that it was already kind of useable. Does OCaml 4.01 have improved support for this style of writing syntax extensions? Is anyone using this mechanism now instead of camlp4 or is camlp4 still the recommended way to write syntax extensions for OCaml?

Solothurn answered 10/10, 2013 at 23:13 Comment(0)
H
10

The work on "(attributes, quotations, etc.)" has been done by Alain under the form of a branch of the OCaml compiler sources, named extension-points. Progress on this branch was extensively discussed on the public wg-camlp4 mailing-list, but was not integrated in 4.01. Since the release of 4.01, it has been integrated in trunk (the reference development branch of the compiler), so it should be available for 4.02 (note that major versions currently tend to get released every year).

Alain maintains a form of documentation for extension points in trunk/experimental/frisch/extension_points.txt. It clearly does not cover all the use-cases of Camlp4, but still a large portion of them. Whether you would rather use that is a personal decision to make; the promise is that the slightly more awkward syntax buys you easier deployment and interoperability with tooling and other extensions.

As of 4.00 or 4.01, -ppx is not adapted for syntax extension, you may only process (and possibly filter/transform) syntactically valid OCaml code. It is technically possible to subvert existing OCaml syntax to add new meanings, but I would recommend against this. You should rather wait for 4.02 if you want to use it for syntax extension.

Helldiver answered 11/10, 2013 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.