OCaml Weekly News

Previous Week Up Next Week


Here is the latest OCaml Weekly News, for the week of December 07 to 14, 2021.

Table of Contents

kqueue-ml 0.2.0 and poll 0.1.0

Anurag Soni announced

I'd like to announce new releases for kqueue-ml (version 0.2.0) and an initial release of poll (version 0.1.0).

Kqueue-ml: Thin bindings to the kqueue event notification system. Changes since the last release:

  • Remove dependency on ctypes
  • Limit support to 64 bit systems
  • Adds constant values to be used as filter flags in the public API

Installation: opam install kqueue

Caveat: This is again mostly tested on macOS, but I plan to work on testing and fixing bugs for getting the library to work well on the various BSD systems, so please open issues if you use it on a BSD system and notice problems (Thanks!).

Poll: Portable OCaml interface to macOS/Linux/Windows native IO event notification mechanisms

Installation: opam install poll

This is the first release of poll, which builds on top of kqueue-ml and adds bindings to the system IO event notifications on linux and windows to provide a portable polling interface. It uses kqueue on macOS, epoll on linux, and uses wepoll on windows so it can leverage IOCP on windows instead of select. All io events will be level triggered, i.e. there will be a notification as long as the file descriptor being watched is ready to read/write.

If you experience any problems, please open an issue on the Github Issue tracker :slightly_smiling_face:

SWIPl-OCaml v0.5 - Never write your own unification algorithms again!

Kiran Gopinathan announced

Hey all! I am just posting to announce a new package I've been working on: OCaml bindings to SWI-Prolog (ver 8.5 or higher)!


It's currently in the process of being submitted to OPAM, but it's my first time writing a package with bindings to C (using ctypes), so some further changes might be needed? maybe?, but you can find the source code repository here: repo/github mirror.

As a sneak peek of what the API looks like, here's a hello world:

(* initialise SWIProlog *)
let () = Swipl.initialise ()
(* setup the prolog database with some facts *)
let () = Swipl.load_source "hello :- writeln('hello world')."
(* construct a Swipl term in OCaml *)
let hello = Swipl.Syntax.(!"hello")
(* send the term to the Prolog engine *)
let () = Swipl.with_ctx @@ fun ctx -> Swipl.call ctx hello

I've taken care to provide some detailed documentation + quick start guide using odoc (see https://gopiandcode.github.io/SWIPL-OCaml/swipl/index.html) - the quick start guide shows a step by step walkthrough on using the library to write a type inference algorithm for lambda calculus using OCaml+Prolog (no need to write your own UF).

Anyway, hope this might be useful for others - I have spent way too long racking my brains on writing dumb custom unification algorithms, but now, no more!

Kiran Gopinathan later added

Here's another example that might be interesting for those who have experience with SWI-Prolog.

You can even get native interaction with CHR: https://en.wikipedia.org/wiki/Constraint_Handling_Rules is a very elegant framework which comes bundled with SWI Prolog that allows users to write complex domain specific constraint solving engines in a concise declaritive way.

Here's a CHR system that models the interaction between salt and water (basic I know, but look up CHR to see some more powerful examples):

let () = Swipl.load_source "
:- use_module(library(chr)).

:- chr_constraint salt/0, water/0, salt_water/0.

salt, water <=> salt_water.

reducesTo_(Goal, C) :-
reducesTo(Goal, Constraints) :-
        findall(Constraint, reducesTo_(Goal, Constraint), Constraints).

Which we can then embed into OCaml using the following code:

let solve_constraints ls =
  (* Create a new term variable context *)
  Swipl.with_ctx (fun ctx ->
    (* create a term for the result *)
    let result = Swipl.fresh ctx in
    (* encode the constraint store *)
    let goal = encode ls in
    (* send the query to the Prolog engine *)
    Swipl.call ctx (reducesTo goal result);
    (* extract the result *)
    decode ctx result
(* val solve_constraints: t list -> t list *)

(Again, some steps have been omitted for brevity, and you should check out the quick start guide for a step by step walkthrough).

opam 2.1.2

Kate announced

We are pleased to announce the minor release of opam 2.1.2.

This opam release consists of backported fixes, including:

  • Fallback on dnf if yum does not exist on RHEL-based systems (#4825)
  • Use --no-depexts in CLI 2.0 mode. This further improves the use of opam 2.1 as a drop-in replacement for opam 2.0 in CI, for example with setup-ocaml in GitHub Actions. (#4908)

To upgrade simply run:

bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh) --version 2.1.2"

Set up OCaml 2.0.0-beta10

Sora Morimoto announced


  • Added "extends" experimentally.


  • Remove some hacks as --no-depexts is now used in CLI 2.0 mode from opam 2.1.2.


A hassle-free setup to release binaries for different platforms: the opam release process experiment

Kate announced

On top of the opam 2.1.2 announcement, I’d like share an experiment with the opam release script used for this release.

As you might know, for each releases of opam we provide pre-compiled binaries for ease of use. We’ve had a release script which up to this point required a specific setup to get it running correctly. For instance we had to setup a local OpenBSD machine (possibliy virtualised), a macOS/x86_64 machine and a macOS/arm64. This setup is rather tedious to reproduce.

To improve this situation I’ve experimented over the past week with QEMU and Rosetta 2 to make it a "one click script":


This change makes so that the script now only requires a macOS/arm64. From there you can:

  • compile locally for macOS/arm64 binaries
  • compile locally for macOS/x86_64 binaries (using Rosetta 2)
  • compile for BSDs (using QEMU)
  • compile for Linux (using Docker)

With this, the binaries for this release have been compiled with this more reproducible setup, and now include FreeBSD/x86_64 binaries as well :sparkles:

If someone wants to have a similar setup to distribute binaries here is the git repository (using Git LFS to store the large files). Feel free to use and experiment with it:


For now it only has OpenBSD/x86_64 and FreeBSD/x86_64 images but it could theoretically have more. Although I’m not accepting PRs for now (for obvious security reasons), I’m open to suggestions to add more platforms. See the README for high level details about the setup.

Set up OCaml 2.0.0-beta11

Sora Morimoto announced


  • Add support for more styles for the ocamlformat configuration in lint-fmt action.


What's the best way to save an huge amount of data in a file

Deep in this thread, Simon Cruanes announced

What a coincidence, I wrote an Avro library very recently. The paint is still fresh. However, it might be worth giving it a try as it's exactly the targeted use case: many rows of relatively simple data, encoded as binary; it also supports gzip compression (per "block" of N many rows, with N configurable). And there's no need to worry about endianess.

It typically uses code generation from a schema (a json file).

There's libraries for Avro in java (with all the Spark ecosystem) and also python (see "fastavro").

p5scm 0.1.0

Jason Nielsen announced

I’ve released p5scm which is now up on opam. It is a scheme-like implementation on top of camlp5's pa_schemer.ml extension. I know that camlp5 isn't the cool kid on the block these days but it is a powerful tool and pretty cool in my estimation ;-).

nanoid 1.0.0

mefyl announced

I'm pleased to announce the release of nanoid 1.0.0. NanoID are popular unique ids amongst the javascript ecosystem. This library brings an equivalent native implementation and a virtual library to transparently branch between the native implementation and the original javascript one. The intent is to enable pieces of code generating such ids to be moved transparently between frontend and backend of a web stack.

This is an humble first contribution to gain some experience and will hopefully be followed by more of our internal developments.

Other OCaml News

From the ocamlcore planet blog

Here are links from many OCaml blogs aggregated at OCaml Planet.


If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.