OPAM package: ocaml-monadic

Hello! I was just repackaging a little library for OPAM 2 the other day when one of the repository maintainers pointed out that I should probably make mention of it on this forum (given that I never have). The package name is “ocaml-monadic”; it provides ppx extensions for monadic syntax in a way that blends with OCaml’s existing grammar. Here’s a link:

I optimistically anticipate the following questions enough to provide answers:

Q1. Why?
A1. Because switching between monadic and non-monadic syntax shouldn’t require rewriting everything. Also because I wanted to learn PPX extensions in 2015. :slight_smile:

Q2. Does the library require or use any specific library when dealing with monads?
A2. No. It just assumes the locally-scoped use of the names “bind” and, in some cases, “zero”.

Q3. How is this different from Jane Street’s ppx_let library?
A3. There are some miscellaneous differences ("%map" in ppx_let vs. “%orzero” in ocaml-monadic), but they’re largely the same idea. Their first versions were released at roughly the same time.

2 Likes

Note that monadic and applicative notations will be directly supported by the compiler itself starting from 4.08 .

5 Likes

I hadn’t read about that; thanks for calling it out. :slight_smile: I note that, as is appropriate for a core language extension, the proposed feature set is quite conservative. Both ppx_let and ocaml-monadic support a larger set of monadic features (which is appropriate for a library). That said, I’ll have to bear in mind that later versions of OCaml should desugar to appropriate uses of let* in order to be compatible with whatever error hinting or other ppx packages might become available. Thanks again for the pointer!

1 Like

One upside to ocaml-monadic (and ppx_let and lwt_ppx) compared with 4.08’s let operators is support for binding in matches. While there is a PR for match operators in OCaml it’s not clear when it will land.

2 Likes