OCaml Weekly News

Previous Week Up Next Week


Here is the latest OCaml Weekly News, for the week of March 14 to 21, 2023.

Table of Contents

Js_of_ocaml 5.1

Hhugo announced

I’m pleased to announce the release of js_of_ocaml 5.1. It should soon be able available in opam.

Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js.

This release includes many significant changes. Here are some of the notable ones:

  • Js_of_ocaml now understands most es6 features (but import and export)
  • JavaScript files generated by js_of_ocaml are now UTF-8 encoded.
  • Change the memory representation of OCaml strings to use JS ones. String still represent sequences of bytes and only contains codepoints in the range [0-255].
  • Improved support for OCaml 5 effects, performing partial CPS transformation to significantly improve perfs (see http://ocsigen.org/js_of_ocaml/5.1.0/manual/performances)
  • Various improvements to make the compiler faster.
  • Separate compilation only link compilation units that are needed, similar to ocamlc, and generate much smaller js files

See the Changelog for other changes.

Petrol 1.2.0 release - Postgres Support + User-extensible types

Kiran Gopinathan announced

I’m pleased to announce the latest release of Petrol - A high level typed SQL API for OCaml (in the process of being published to opam).

This latest release is exciting as it now adds Postgresql support (previously Petrol only supported Sqlite3).

Petrol makes using SQL from OCaml a breeze:

open Petrol
open Petrol.Sqlite3

(* define a new schema *)
let schema = StaticSchema.init ()

(* declare a table *)
let example_table, Expr.[name; age] =
    StaticSchema.declare_table schema ~name:"example"
        field "name" ~ty:Type.text;
        field "age" ~ty:Type.int

and here’s how you write queries:

(* create a query *)
let insert_person ~name:n ~age:a db =
    Query.insert ~table:example_table
            name := s n;
            age := i a
    |> Request.make_zero
    |> Petrol.exec db

Petrol compiles down to Caqti queries under the hood, and comes with a nifty migration system built-in, so you can seamlesly update your database tables without disrupting end users:

(* declare a table with a migration for a new [age] column in version 1.2.0 *)
let t, Expr.[id;age;url] =
   VersionedSchema.declare_table db ~name:"person"
       field ~constraints:[primary_key ~name:"bookmark_id" ()] "id" ~ty:Type.int;
       field "age" ~ty:Type.int;
       field "url" ~ty:Type.text;
     ~migrations:[v_1_2_0, [
       Caqti_request.Infix.(Caqti_type.unit ->. Caqti_type.unit)
         {sql|ALTER TABLE person ADD COLUMN age INTEGER DEFAULT 1000|sql}

This and more is explained in the documentation, along with a nifty quick-starter guide: https://gopiandcode.github.io/petrol/petrol/index.html

I’ve spent some time tuning the documentation to make it easy to pick up!

You may also want to check out the tests to see it in action: https://github.com/Gopiandcode/petrol/tree/master/test

Previous discussion: https://discuss.ocaml.org/t/ann-petrol-1-0-0-a-high-level-typed-sql-api-for-ocaml-designed-to-go-fast/11166

Docfd: TUI fuzzy document finder 0.2.3

Darren announced

I’m happy to share Docfd, an interactive TUI tool finding the text file you need quickly.

(Will submit to opam when time frees up a bit.)

Screenshots and interface

Searching left is in the repo root


Searching [github] in the repo root


The TUI is divided into three sections:

  • Left is the list of documents which satisfy the search constraints
  • Top right is the preview of the document
  • Bottom right is the ranked content search result list
  • Bottom bar is the search interface


Docfd operates in modes, the initial mode is NAVIGATION mode


  • Scroll down the document list
    • j or down arrow
    • Scroll down with mouse wheel when hovering above the area
  • Scroll up the document list
    • k or up arrow
    • Scroll up with mouse wheel when hovering above the area
  • Scroll down the content search result list
    • Shift~+~j or ~Shift~+Down arrow
    • Scroll down with mouse wheel when hovering above the area
  • Scroll up the document list
    • Shift~+~k or ~Shift~+Up arrow
    • Scroll up with mouse wheel when hovering above the area
  • Open document
    • Enter
      • Docfd tries to use $VISUAL first, if that fails then Docfd tries $EDITOR
  • Switch to CONTENT SEARCH mode
    • /
  • Exit Docfd
    • q or Ctrl+c


  • Content search field is active in this mode
  • Enter to confirm search constraints and exit search mode


  • Docfd is focused on typical desktop use, so simplicity of components is often favoured over strict performance
    • That being said, the in-memory index and search should still be performant enough
  • No on-disk index is built

OCamlot - Activitypub server written in OCaml

Kiran Gopinathan announced

I’m pleased to announce the release of a project that I’ve been working on, on-and-off for a while now: an activitypub server in OCaml — OCamlot.


It’s wildly incomplete, and currently only the bare-bones minimum to be a considered an activitypub server, but it’s coming along nicely.

Currently it supports:

  • profiles, custom profile pictures, about
  • likes, reposts
  • replies

and that’s all.

Some screenshots:

  • Feed 65e8cbb291c93f6bb1592e7aba861a09879559a9_2_1034x484.png
  • Writing replies: be50c1293ab9fd424c10b5855a0ab0402695e56c_2_1034x430.png
  • Listing users: 861c06d96320d80df7cdfce33825ab3dd911a7c8_2_1034x214.png
  • Profile page: ca5d18579af38d44c57fb2d1a813ca5ca5ac85c3_2_1034x386.png
  • Post replies 079f47b31fd8f54bf3d4fc1943662fb44355af19_2_1034x398.png

Now, the things that this community would care about:

Seeing as there has been some interest in this community recently about activitypub integration in OCaml, I figured this might be interesting.

I have an instance running on over at https://ocamlot.xyz – as a warning, I’ve done most of my testing locally using pleroma, so there may be some slight issues interacting with other server implementations at the moment.

Also would be happy to field any questions regarding navigating the activitypub spec as well. I plan to write up my experiences somewhere at some point in the future.

new versions of VS Code extensions Alcotest and Expect and Inline tests, now on Open VSX too

Roland Csaszar announced

I’ve just updated both VS Code testing extensions, as of now they are available at the Open VSX Registry too.

Bugfixes: The Opam environment of the project’s root is used, so the Dune executable in the sandbox of the project directory is used by default if such a sandbox exists. Otherwise the environment of the current Opam switch. If Dune does not work (a call of dune --version fails), an error message box is displayed.

Expect & Inline PPX

Alcotest & Inline Alcotest


  • Add error message window if dune does not work in a workspace.
  • Bugfixes
    • Use the current Opam environment to be able to use local executables like dune.
  • Internal Changes
    • Add tests to check the parsing of opam env.

Autofonce, a modern runner for GNU Autotests suites

Fabrice Le Fessant announced

I am not sure it might be helpful to the OCaml community, as we already have well integrated test frameworks, but here is a tool I wrote in OCaml to work with GNU projects: autofonce is a modern runner for testsuites created for the GNU Autoconf tools.

Compared to Autoconf tools, its main features are:

  • improved terminal output
  • automatic parallel execution
  • promotion of tests results to fix tests
  • extended syntax
  • filtering by keywords, numbers and ranges
  • execution from any project directory

A typical Autoconf test looks like:

# Start of a test, and the name that will be displayed
AT_SETUP([Example test])

# can be used to select tests to run:
AT_KEYWORDS([example test autofonce])

# create a file ~file~ with its content
AT_DATA([file], [
content of file
on multiple lines

# call some command, check its exit code, stdout, stderr
AT_CHECK([cat file], [0], [stdout of my command], [stderr of my command])
# you can do more, ignore some results, run more tests in case of failure, etc.

# end of the test

I personally like the syntax better than the one of cram tests, though there is some weird escaping issues with brackets (see the section in the doc).

Compatibility with Autoconf is only partial, as it uses a grammar interpretation of what should actually be m4 macros, but it was good enough to run the full GnuCOBOL testsuite after a few fixes (that actually improved the testsuite).

The package is on Opam, but sources, documentation and static binaries are available from Github:


Release of piece_rope 0.9.0

Humza Shahid announced

I’m not sure how useful this is to others, but I published my first open source package to opam which can be used by anyone interested in it.

It is the same data structure used for editing text in VS Code [1] and AbiWord [2], with a few modifications to make it persistent and functional.

It provides some nice features on top which include:

  • Serialising and deserialising the structure to a file for persistent undo/redo.
  • Translating between offsets of different Unicode encodings (UTF-8, UTF-16 and UTF-32) for interaction with external systems and languages.
  • There is a computationally expensive function to rebuild the structure, optimising it for memory usage and performance. (The idea was to use this in a GUI app when the user is inactive and rebuilding in that case - the core structure is fast but the perfectionist in me wanted it to be as fast and lean in memory as possible.)

There are some similar packages others may find useful like Zed which are a more battle-tested implementation of a similar-but-not-quite-the-same data structure as this is a new implementation.

Feel free to comment or open issues for any bugs you find during usage. Hopefully someone else out there will find this useful too.


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.