Stdcompat, a compatibility module for OCaml standard library

I am pleased to announce Stdcompat: a compatibility module for OCaml standard library.

Stdcompat.* redefines (most of the) symbols available in the standard library of OCaml 4.06.0, such as List.find_opt, floatarray, bytes, Uchar.t, etc., and compiles on all versions of OCaml since 3.12.0.

If the version of OCaml is recent enough, these types and values are just aliases to the corresponding symbols of the standard library. Otherwise, they are redefined. For instance, Stdcompat.floatarray is an alias for floatarray with OCaml 4.06.0 and for float array with OCaml 4.05.0 and older.

Sub-modules signatures include the signatures of the standard library modules, in order to allow Stdcompat to be opened globally if preferred. For instance, Stdcompat.List reexports all the symbols of List. See the.mlip file or the preprocessed .mli and the generated documentation for the complete list of available symbols.

The provided redefinitions do not make anything magic with the internal data structures: some of them are not as efficient as the ones of the standard library (for instance, Hashtbl.filter_map_inplace may rebuild the hash-table), and can be even insecure (for instance, seeds are ignored for hash tables prior OCaml 4.00). This is a design choice that can possibly change in the future. Of course, these lesser redefinitions are used only if the OCaml version is not recent enough.

The module is intended to follow future changes of the standard library, and the API can change, for instance if some symbols become deprecated. However, I will try to keep the ability to be compiled on old versions of OCaml (at least 3.12.0).

GitHub repository: https://github.com/thierry-martinez/stdcompat
Available in OPAM: opam install stdcompat

Happy hacking!

11 Likes

Hi Thierry, based on your intentions of keeping backwards-compatibility, I have a feeling you’ve been in some discussions about possible changes to the standard library. I would be very interested to have a look at those–could you give me a pointer? Thanks