OCaml Weekly News

Previous Week Up Next Week


Here is the latest OCaml Weekly News, for the week of November 01 to 08, 2022.

Table of Contents

What’s the well-liked GUI toolkit these days for OCaml

Chet Murthy asked

I’m looking to display PNG images in a window from OCaml code, and would like to put a little window around it with a button to close the window, maybe support resizing, stuff like that. I know about Lablgtk (and used it lo these many years ago). Is that still the well-liked thing?

I’m of half a mind to just call www-browser foo.png and let the local web browser deal with it, but that’d doesn’t work so well when you’re not on the same machine as the display, ah well.

Carmelo Piccione suggested

I have very little experience in this domain with OCaml so take this answer with a grain of salt, but I would probably at least try using lablqml.

I know some developers have attempted to write a pure functional gui api in OCaml from scratch but I can’t recall what those projects are called. Someone else on this forum will hopefully dig it up for you.

Good luck and report back with which one you end up choosing!

(my guess is targeting the web browser is a lot easier than a native gui these days, unfortunately)

sanette also suggested

if you allow me to advertise a library of mine, I think that bogue should be able to do what you want.

Vladimir Keleshev said

I’m pretty sure that raylib-ocaml by @tjammer can manage this.

David Declerck suggested

You could use OCaml-Canvas (documentation). It’s a new vector graphics library I’m developing for OCaml, and among its features, it can load PNGs and handle windows and mouse/keyboard events (using React). It works on Linux/macOS/Windows and also in web browsers (through HTML5 canvases, hence the similar interface).

It has not been “officially” released yet, but should be soon enough. Don’t hesitate to experiment with it !

Here’s how you can use it to load and display a PNG :

open OcamlCanvas.V1

let () =

  Backend.init ();

  let c = Canvas.createFramed "Image view" ~pos:(300, 200) ~size:(400, 400) in

  Canvas.show c;

  let e1 =
    React.E.map (fun img ->
        let size = ImageData.getSize img in
        Canvas.setSize c size;
        Canvas.putImageData c ~dpos:(0, 0) img ~spos:(0, 0) ~size
      ) (ImageData.createFromPNG "assets/image.png")

  let e2 =
    React.E.map (fun _ ->
        Backend.stop ()
      ) Event.close

  Backend.run (fun () -> ignore e1; ignore e2)

Chet Murthy then clarified

With so many good answers, I thought I’d ask about more functionality: This image is a visualization of a quantum circuit. It’s built out of a bunch of boxes-and-lines, using the Python matplotlib library. I’d like to generate such images from OCaml. Obviously, I could just call Python (and heck, just call Qiskit’s visualization library), but … I’m picky and want to do it without Python.


Is there a nice boxes-and-lines drawing package, that I might be able to use to draw such a thing? For reference, there’s a Latex package that uses a latex \xymatrix environment to draw passable circuits:


and I can generate the inputs to that already. So this is really a “stretch goal” grin.

Edwin Török suggested

You could try https://erratique.ch/software/vg/doc/Vg/index.html#basics, it should have most of the primitives you’d need to compose such an image, and although it doesn’t seem to have builtin support for drawing aligned to a grid, there is a combinator to `move` a piece of an image, so should be possible to define something higher level that computes the coordinates needed for that. It can output SVG which will probably be useful for rendering the drawings on the web.

sanette also replied

it does not fully answer your question, but you might be interested in this post. The question was a bit similar, but with less sophisticated graphics. Of course, in principle you can use SDL primitives to obtain whatever you need, but it will require some work. In your case, since you don’t need animations or fancy stuff like this, I suppose it would be quite appropriate to use ocaml-cairo to produce your image. This can be integrated directly within bogue with bogue-cairo

zapashcanon suggested

Maybe Mlpost could work for you ? See github and the paper (in french).

Mini-dalle in OCaml

Arul announced

I wanted to announce my work of porting mini-dalle to OCaml https://github.com/ArulselvanMadhavan/mini_dalle

I’m looking for feedback as I look to publish this to opam in the near future.

Thanks @laurent for suggesting that I share this here!

Danielo Rodríguez asked and Arul replied

Yep, I saw that, but does it require any extra setup? Training files, or AI models or something like that? Is it supposed to be executed in an environment like Google colab or something? Sorry, I just have very little experience with AI

I see. I could write up a section on what it does.

All the user has to do is build the docker image with “make mini-dalle” and run the dune exec command as shown in the Readme.

In the background this is what happens:

  1. On the first run, It downloads pretrained weights from a repo and saves them in a directory
  2. Download takes some time around 10 mins and approx 7GB space
  3. It then, runs the inference path by converting text to text tokens, text tokens to image tokens and image tokens to image. This takes about 30 seconds on a A100 GPU. On the CPU, it will take longer around 5-7 mins
  4. In the subsequent runs, it just uses the downloaded weights and starts running from step 3.

I can add a notebook in the future. Right now, it just works from the command line. Hope it helps!

Mirage retreat October 3rd - 9th

Continuing this thread, Hannes Mehnert announced

To follow up, we have various reports from participants about the retreat:

Enjoy reading, and take care. :smiley: :camel: :desert: :ocean: :surfing_woman:

setup-dkml.yml GitHub Actions workflow for distributing binaries

jbeckford announced

There is a new major version 1.1.0 available. It is not backwards-compatible but it adds:

  • Supports GitLab CI/CD in addition to GitHub Actions
  • Supports testing/troubleshooting/developing your CI on your desktop (macOS, Linux if you have Docker, and Windows if you have Visual Studio). You do not need DKML installed on your machine.

The only known issue is that GitLab CI/CD sometimes kills the Windows build of the OCaml compiler when using the shared GitLab SaaS runner; retrying the job usually fixes that.

If you had used the v0 series of the workflow, that version will continue to be supported for a few months but won’t get any updates unless the update is critical.


Upgrading? The most straightforward way is to introduce 1.1.0 into your project (see the link above) and only after it is working you should remove the v0 GitHub child workflow.


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.