OCaml Weekly News

Previous Week Up Next Week


Here is the latest OCaml Weekly News, for the week of May 28 to June 04, 2019.

Table of Contents

Is there a tool to do automatic serialization/deserialization AND automatic schema migration (from OCaml types)?

Deep in this thread, Jared Forsyth announced

Well I went ahead and made one 😅 would love to hear your thoughts


A module for printing a tree to a terminal like the 'tree' command

Martin Jambon announced

Today I made a module for printing trees in a readable fashion. The output looks like the output of the tree command:


It works on any data structure that supports get_name and get_children functions and depends on nothing else than the OCaml standard library.

I'm releasing it into the Public Domain in the hope others find it useful. Anyone is welcome to include it in their projects or turn it into a proper open-source project that they maintain.

ppx_enum v0.0.1

James Owen announced

Cryptosense is happy to announce the initial release of ppx_enum !

ppx_enum is a ppx to derive enum-like modules from variant definitions. It’s inspired by the enum declaration syntax in Python, and various other languages.

Enums are bare variants that are intended to represent a flag that can have more values than just true and false. The idea is that ppx_enum makes it easier to work with enums, in particular handling the conversion to and from strings. This is useful when (de)serializing values (for example, when serializing to store in a database), and cuts down on repetitive boilerplate code.

Consider the following simple example:

type my_enum =
  | Foo
  | Bar
  | Baz
[@@deriving enum]

The use of [@@deriving enum] will generate the following functions:

let my_enum_to_string = function
  | Foo -> "Foo"
  | Bar -> "Bar"
  | Baz -> "Baz"

let my_enum_from_string = function
  | "Foo" -> Ok Foo
  | "Bar" -> Ok Bar
  | "Foo" -> Ok Foo
  | _ -> Error ...

let my_enum_from_string_exn = function
  | "Foo" -> Foo
  | "Bar" -> Bar
  | "Foo" -> Foo
  | _ -> invalid_arg ...

Since we found this was something we were doing a lot in our code, the use of ppx_enum has improved readability, reduced the need for boilerplate tests and made the conversions less error prone (as it eliminates bugs caused by typos in the string conversion methods).

It’s in a beta release at this point so any feedback is appreciated!

You can find it on github and opam!

Dungeon crawler game

Continuing this thread, Bramford Horton said

Cool. I see you've made heavy use of the object system. If you're interested in games built using the more idiomatic functional/ocaml approach (i.e. modules), you should check out a-nikolaev/wanderers.

I also wrote bramford/2d-exploration-game - a simple terminal/ncurses game while I was learning ocaml. I tried a couple of different approaches using the module system. I never felt that I got it quite right so while it is quite simple, it may not be the best example.

Florent Monnier also said

On my side I started a shmup game with abstract graphics because I'm fond of Kenta Cho games, not yet in a git repository, I put it in a gist: https://gist.github.com/fccm/ade9aee7b4594dc9c130b40098ad92ab

Quite functional too, only shot and missed variables are imperative.

Florent Monnier then added

I updated it to remove the dependencies on ageom and timeline by including the pieces of code used: shmup_av10.ml

As there is only one source code file, you can run it directly with ocaml:

opam install ocamlsdl2

If you're using SDL2 version 2.0.9, or if you installed an older version:

opam install ocamlsdl2.0.02

Then you can run the game with:

eval $(opam env)
ocaml -I $(ocamlfind query sdl2) sdl2.cma shmup_av10.ml

I created a basic webpage for this game, there are screenshots and an executable binary for Windows.

Coccinelle engineer position

Julia Lawall announced

Despite our old fashioned web site (http://coccinelle.lip6.fr) and insufficient manpower to accept many external contributions, the Coccinelle team is looking for an engineer to work on the Cocinelle implementation for 2 years starting in September 2019. Coccinelle is a program transformation tool for C code, written in OCaml, primarily targeting the Linux kernel. The position will be at Inria-Paris (concretely at LIP6). A masters degree is required (relevant work experience might be acceptable). Good knowledge of OCaml or another functional programming language, familiarity with C code, and experience with program analysis (eg in a compiler course) would be helpful. There is no constraint on nationality or requirement to speak French. Please contact julia.lawall@lip6.fr if interested.

ppx_bsx 2.0.0

Chen Xian-an announced

If you like me, want to do ReasonReact projects in OCaml but not Reason, I'm happy to announce the release of ppx_bsx: https://github.com/cxa/ppx_bsx.

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.