Is camlp4 being deprecated in favor of ppx?

I haven’t been following OCaml culture much for the last couple of years, but the other day when I brought everything up to the latest version with opam, I was playing with a package that required a camlp4 syntax extension in utop (version 2.0.1 with OCaml 4.05.0). When I typed :


I got:

utop was built without camlp4 support.

Looking into it a bit, I found that camlp4 support was removed in utop 2.0.0. Which is unfortunate because a lot of docs (including the 1st and 2nd editions of Real World OCaml) rely on camlp4 support in utop.

I recall a few years back that ppx was introduced as an easier alternative to camlp4, but it seemed that they would both sort of co-exist (you can make much more natural-looking syntax extensions in camlp4 when compared to ppx, it seems). camlp4 was removed from the main distribution and became a library, but I didn’t get the impression that it would completely go away.

So are other projects also abandoning camlp4 as utop did? What are the cultural trends here?

(It looks like we can still use camlp4 syntax extensions in the standard OCaml REPL, but it’s not nearly as featurefull as utop.)

I think so, the trend is more recent libraries tend to stay away from camlp4 as camlp4 is deprecated. For instance this is an Lwt issue that removes all mentions of camlp4 from the manual.

1 Like

The title is correct. You should not base new code on camlp4. Utop and Merlin lack of support are just a few examples.

PPX rewitters are easier to write and integrate well with the Ast. You can group a bunch of them and process everything with one executable. This makes them easier to integrate with tooling. Most importantly, if you don’t define the right setup to activate a PPX all you get is a warning, not a hard failure.

They are great, I just wish they looked a bit better. If we could use PPX behaving like function application using the same syntax as Rust’s macros, it would be awesome.

Yes, I also wish they looked better. I understand the advantages of PPX over camlp4, but the syntax from the users perspective looks horrendous.

Are there any good docs about moving from camlp4 to PPX? Also, any plans to update documentation that depends on camlp4 being available (as in even the revised online Real World OCaml)? (think of the newbies)

A few things that have been happening recently might help:

  • the relevant ppx libraries are in a few organisation, and so are at least in one place. Unfortunately, there is still a confusing set of options to use as the baseline for building ppx rewriters (since the community essentially learnt what would work over a few years of porting from camlp4). Documentation is thin on the ground, but if anyone would like to step up to do the research and start a migration document of camlp4->ppx, it would be massively appreciated :slight_smile:

  • RWO is being refreshed to a v2 at the moment and the newer version is snapshotted at


Anil, for the first edition of RWO there was a way to add annotations/notes to the text via github (IIRC) - is that possible with V2?

Phil, there was indeed, but we are trying something a little different involving integration this time around. The problem with the GitHub commenting is that it required vast privilege on the GitHub API level, and I am reluctant to handle those tokens or require them for casual commenters. Now that we have this forum, the commenting will be less fine-grained but more accessible to casual commenters. We’re working on a first release of that very soon now.