OCaml Weekly News

Previous Week Up Next Week

Hello

Here is the latest OCaml Weekly News, for the week of September 27 to October 04, 2022.

Table of Contents

How to dump many floats in binary format so that OCaml can read them in later

A long time ago, UnixJunkie asked

I need to write out to disk many floats from a Python script (but that could also be from a C program). Later, I would like to read them as 32bit floats in OCaml. What is the format I should use? I want to use 32bit floats, because 64bit floats would be two times more data. I guess 32 bits precision is way enough for what I am doing.

pukkamustard replied

Maybe something like CBOR would work for you? It’s a standardized binary serialization format that has a dedicated datatype for 32bit floats and there are implementations for OCaml and Python (and many other languages).

Shameless plug: I am the author of a CBOR implementation for OCaml: https://opam.ocaml.org/packages/cborl/

UnixJunkie said and Xavier Leroy replide

Nice, so for integers, I should be using: Stdlib.output_binary_int and input_binary_int.

No. These functions operate on the low 32 bits of values of type int, meaning that on 32-bit platforms you’ll lose some bits.

For reliable encoding/decoding of 32 and 64-bit integers, please use Bytes.{get,set}_int{32,64}_{le,be,ne}, which also let you control the endianness you want to use.

Carmelo Piccione said

This might be too heavy handed for you but hdf5 is a decent choice for serializing and loading back up large numerical datasets, especially if your data is shaped like a typical dataframe.

It has a proven track record as it is often used by the scientific computing community and the finance industry as well. They like the fact that it’s high performance, standardized, and supports hierarchies and thus multiple datasets within one file. You can also memory map to it or use filters and chunking to avoid loading the entire file.

The biggest negative: there is only a complex C library implementation of it which is inevitably wrapped to other languages, including ocaml.

Beta of neovim treesitter-reason

Danielo Rodríguez announced

I’m happy to share that my neovim plugin for adding tree-sitter support for reason (which is a fork of the rescript tree-sitter plugin for neovim) has now reached an “usable” state. It still needs development, and there are things that still only make sense for rescript, but it is already helping me in my everyday work. Everybody is welcome to contribute if you find it valuable. Not sure if this is interesting in an Ocaml forum, but I guess that some people may use the reason syntax, and since there is no Reason forum anymore, I will be posting it here and in rescript one.

Here is the project: https://github.com/danielo515/nvim-treesitter-reason

data-encoding 0.7

Raphaël Proust announced

Version 0.7 of the Data-encoding library has just been released.

Data-encoding is a library for describing binary and JSON encodings for your various OCaml types and for serialising to and deserialising from those descriptions.

The library is used within the Tezos project. It is hosted on Gitlab under the MIT License. It is distributed on opam.

New OCaml meetup group in Toulouse (in French)

R. Boujbel announced

Le premier meetup se tiendra le 11 octobre à 18h à la Manufacture des Tabacs. Merci de nous informer de votre présence en vous inscrivant sur cette page contenant les détails de la session.

Au plaisir de vous y retrouver !

opam-mirror: a MirageOS unikernel that provides an opam repository and cache

Hannes Mehnert announced

We at robur developed opam-mirror in the last month and run a public opam mirror at https://opam.robur.coop (updated hourly).

This was nice collaborative work with @reynir and @dinosaure, and we have an article https://hannes.robur.coop/Posts/OpamMirror and the source code https://git.robur.io/robur/opam-mirror

Enjoy reading, feedback welcome. :D

Aches.1.0.0, Ringo.1.0.0

Raphaël Proust announced

Version 1.0.0 of the Aches and Ringo libraries have just been released.

Aches provide various caches (Sets, Maps) with various policies (FIFO/LIFO, Strong/Weak, etc.). It also makes a distinctions between value caches (caches for in-memory values which are ultimately cleaned by the GC) and resource caches (caches which model resources such as file-descriptors which need some cleaning-up), providing different mechanisms for retrieval to help ensure all resources are properly cleaned as needed.

Ringo is a support library for Aches which may also be of interest to other developers. It provides doubly-linked lists and rings.

Finally, the Aches-lwt library provides caches for values which can take some time to obtain, in the form of Lwt promises — for instance, the content of a file stored on a remote machine.

This is the first stable release of Ringo, Aches, and Aches-lwt; future versions will adhere to the semantic versioning scheme.

The libraries are used within the Tezos project. They are hosted on a single repository on Gitlab under the MIT License. They are distributed on opam.

Multicore with opam–instructions?

Yawar Amin announced

If anyone is interested–I wrote a post with a Multicore/Eio experiment: https://dev.to/yawaramin/practical-ocaml-multicore-edition-3gf2

Other OCaml News

From the ocaml.org blog

Here are links from many OCaml blogs aggregated at the ocaml.org blog.

Old CWN

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.