I am currently doing an academic project that will require access to the parse tree for algebraic effects and handlers using ppx. Currently I was not able to find any solution using ppxlibs or compiler-libs, is there any project that has extended ppx tools to give access to the constructors related to effects?
If that is not the case, @mariopereira and I are willing to extend (at least minimally) the existing ppx ecosystem.
Note that OCaml 5.0 does not include any additional syntax for effect handlers: the Parsetree is identical to that of 4.14.
The title is a bit misleading, we are working in the 4.12.0+effects+domains switch, which does have syntactic support for effects and handlers. This means that when we try to install ppx lib we get the following error:
1311 | | Pstr_eval (e, attrs) →
1312 | pp f “@[;;%a@]%a”
1313 | (expression ctxt) e
1314 | (item_attributes ctxt) attrs
1442 | | Pstr_attribute a → floating_attribute ctxt f a
1443 | | Pstr_extension(e, a) →
1444 | item_extension ctxt f e;
1445 | item_attributes ctxt f a
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
Meaning we will need to rewrite ppx lib in order to use it in this switch. This is a bit of a niche problem, but we are wondering if anyone has done anything regarding this.
If I understand correctly
4.12.0+effects+domains was a testbed for lots of the developments that lead to OCaml 5.0, it is not representative of OCaml 5.0 and as @nojb said, in 5.0 there won’t be any syntax extensions for effects.
This doesn’t mean that they won’t be introduced eventually, maybe in future releases and at that time the PPX tooling will most likely support that. It might match the syntax of
4.12.0+effects+domains but it also might not, so I would recommend against using an abandoned prototype to base your work on.
There’s a patch to ppxlib.0.22.0 to make it work with 4.12.0+domains+effects here, but I’d be very surprised if it hasn’t bitrotted with more recent ppxlib releases. As others have noted in this thread, the effect syntax is nice, but has no future in OCaml 5.0, so bear that in mind before using it in new code.