User-friendly continuations over OCaml 5 effects?

Until last year, we used to teach continuations to our students, relying on a simple usage of Oleg Kiselyov’s delimcc library (nothing fancy, just as an introduction). Now that OCaml 5 is here, I was wondering whether someone had developed a PPX or library hiding a bit of the Effect module machinery, to allow a syntax closer in spirit to that of delimcc. I know there have been experiments but is there something sufficiently stable?

1 Like

I believe @avsm has a WIP branch that adds syntax for effect handlers in OCaml 5 with the aim to make it easy for teaching them.

I do indeed have the same problem as @grayswandyr, in that I’m planning on teaching effects/concurrency in my undergraduate courses at Cambridge from next year. I don’t think PPX is satisfactory for teaching due to the cognitive overhead of the syntax.

I’ve got a WIP rebase of the effects syntax by @lpw25 and @kayceesrk from the multicore-ocaml trees over at Commits · avsm/ocaml · GitHub. The original patch wasn’t just a pure syntax change since the type of a continuation has to be taken into account, and so there are changes through the type checker as well.

Not yet clear if this will be suitable for merging, but I’m going to open a PR on ocaml/ocaml just as soon as I shake the out the bugs from my rebase (there have been significant refactorings within the type checker from 4.12->5.2-dev). If it doesn’t make it upstream, then I’m going to maintain it as a patch against 5.1 so I can use it with my course (via a JSOO-compiled toplevel).


I’ve revived some old code that implements delimited control operators (shift/reset, control/prompt) over effect handlers and pushed it as a separate library.

The code was originally developed for the Eff directly in OCaml paper along with Oleg Kiselyov.


That’s great. I’m going to test it right away, thanks.

I also teach continuations to my students :slight_smile: I seem to recall that effects are not sufficient as a drop-in replacement for delimcc because the continuations in effects are one-shot. That wouldn’t work for some of my examples.

Delimited continuations exposed by effect handlers on OCaml 5 are indeed one-shot. However, GitHub - kayceesrk/delimcc_of_fxhandler: Delimcc primitives from OCaml 5 effect handlers provides multishot continuations by building on top of GitHub - dhil/ocaml-multicont: multi-shot continuations in OCaml.


Right, I was thinking of this thread. So I guess as long as you are careful about resources you can do it.

Not just resources. The fact that compiler optimisations break semantics is challenging to get around with careful programming. If you are careful with resources and avoid mutable state, then you will get the right semantics. This isn’t impossible but it is easy to get wrong.

1 Like

Would you mind publishing the package on opam? It’d be easier to ask our sysadmin to install it on our lab machines like (s)he does with other opam packages. (If you can come up with a shorter name for our students to type the lib name, that’d be cool too :wink: )

Happy to. I shall get to it this week.


The package is now on opam


@kayceesrk: Do you happen to have a delimcc-based implementation of the OCaml 5 Effect interface, too? It would occasionally be useful to use Effect in OCaml 4.