Previous week Up Next week


Here is the latest OCaml Weekly News, for the week of March 21 to 28, 2017.

  1. OCaml on the benchmarks game
  2. Exceptions and Gc.
  3. Open 18-month Research Engineer Position on Frama-C/E-ACSL
  4. Transforming side-effects to a monad
  5. Loading .ml in memory to interact with them.
  6. React.js programming in OCaml?
  7. first release of minivpt: a minimalist vantage-point tree implementation in OCaml
  8. BuckleScript 1.6
  9. Ocaml Github Pull Requests
  10. Other OCaml News

OCaml on the benchmarks game


Isaac Gouy announced:
It's been too many years since I mentioned that new and improved OCaml programs
would be welcome contributions to the benchmarks game.

Here are the existing programs:

Here are instructions on how to contribute a program:

Exceptions and Gc.


Continuing this thread, Gabriel Scherer announced:
By the way, the unloading patch is now merged. (In trunk; it should not be part
of the 4.05 release in preparation, but of 4.06 that should hopefully happen six
months after that.)

Open 18-month Research Engineer Position on Frama-C/E-ACSL


Julien Signoles announced:
The Software Reliability Lab at CEA LIST (Paris Saclay, France) is hiring a
18-month research engineer to improve the Frama-C runtime verification plug-in

A full description of the open position is available online:

Feel free to contact me for additional details

Transforming side-effects to a monad


Christoph Höger asked:
this is not entirely OCaml related, but somewhat more general. However,
I hope that someone on that list can give me a pointer on how to proceed.

Assume a simple OCaml program with two primitives that can cause

let counter = ref 0
let incr x = counter := !counter + x ; !counter
let put n = counter := n; !counter
put (5 + let f x = incr x in f 3)

This example can be transformed into a pure program using a counter
monad (using ppx_monadic syntax):

  i <-- let f x = incr x in f 3 ;
  p <-- put (5 + i)
  return p

For a suitable definition of bind and return, both programs behave
equivalently. My question is: How can one automatically translate a
program of the former kind to the latter? I assume, one needs a normal
form that makes the order of evaluation explicit, but which normal form
would that be? Is there a textbook algorithm for that kind of analysis?

any pointers are appreciated
Jeremy Yallop replied:
You might be interested in the following paper, which describes
exactly such a translation:

   Lightweight Monadic Programming in ML
   Nikhil Swamy, Nataliya Guts, Daan Leijen, and Michael Hicks
   ICFP 2011

Loading .ml in memory to interact with them.


Deep in this thread, Oleg said:
> The problem here is that echo (or printf) closes the pipe_in fifo,
> hence sending EOF to the ocaml toplevel. You need to force the fifo to
> somehow remain open.

Eons ago, back in the last century, I wrote a simple tool for that task
to script almost anything from really anything. I used it to drive
Mathematica (on a remote machine) from Emacs and database CLI tools.

(I just realized it has been 20 years...)

React.js programming in OCaml?


Kenichi Asai asked:
What is the best way to do react.js programming as introduced in

in OCaml?  I found the tutorial on the above page written very well,
and I want to do the same thing in OCaml at the similar abstraction
level as in JS.  Any information is welcome.  Thanks in advance.
David Teller replied then Daniel Bünzli said:
> If I recall correctly, React.js is actually a JS port of the following
> OCaml library:
> So that might be what you're looking for :)
I don't think so AFAIK react.js has nothing to do with functional reactive
Zhi An Ng also replied:
The closest thing I know is reason-react, reason is facebook's sugar syntax for
ocaml for the web. Bucklescript, is another javascript backend for ocaml, and
has interop with javascript libraries.

I think the main difference is that [0] allows you to write JSX.

Hongbo Zhang then said:
Indeed, OCaml actually has the official support of ReactJS bindings provided by
Facebook's Reason team and Bloomberg's BuckleScript compiler. According to React
Conf 2017, it is used in production for already half a year and powered a quite
large piece of components in FB's Note ReasonML provides JSX
syntax which is more familiar to ReactJS users, but you can use either Reason
syntax or vanilla OCaml syntax.

first release of minivpt: a minimalist vantage-point tree implementation in OCaml


Francois Berenger announced:
A vantage point tree allows to do fast (but exact) nearest neighbor searches in
a space of any dimension provided that you have a distance function (to measure
the distance between any two points in that space).

The code is here:

The interface looks like this:
type 'a t

val create: ('a -> 'a -> float) -> 'a list -> 'a t

val nearest_neighbor: ('a -> 'a -> float) -> 'a -> 'a t -> float * 'a

val to_list: 'a t -> 'a list

val is_empty: 'a t -> bool

The creation of a vp-tree can take some time.
Queries are supposed to be fast.
In my tests, queries can run several times faster than a brute
force search once you have enough points indexed by your vpt.

The implementation creates an optimal vp-tree; don't use it
on large points set (> 10,000 points).

You can install it via:
$ opam install minivpt

Contributions are very welcome to support large point sets, queries
with a tolerance parameter (as in "only points within distance to query
less than the tolerance"), and returning all points (instead of just one) if
there are several points within the same distance to your query point.

A usage example might be:
let vpt = Vp_tree.create distance_fun points in
let dist_to_query, nearest_point = \
Vp_tree.nearest_neighbor distance_fun query_point vpt in

My implementation follows the paper:
"Data Structures and Algorithms for Nearest Neighbor Search in General Metric
Spaces" by Peter N. Yianilos.

BuckleScript 1.6


Hongbo Zhang announced:
BuckleScript is an optimizing compiler for OCaml to generate readable
JavaScript, it is open sourced by Bloomberg [1].

We are glad to announce 1.6.0, since release 1.5, we have seen significant
external contributions, some of them are even
new to OCaml, this is fantastic! Also there is an small group of people who are
actively working on bindings and utilties:

This release is mostly bug fixes and performance improvement to the build
system, most visible changes:

# Thanks to @glennsl, we have a nice documentation page for the Js bindings: (Note this is still work in
# Much faster build even for `bsb -make-world`, the build system is now
# All error messages from the compiler and build are colorful

Documentation is available here:

To install:
npm install -g bs-platform
Happy hacking in OCaml! -- Hongbo


Ocaml Github Pull Requests

Gabriel Scherer and the editor compiled this list:
Here is a sneak peek at some potential future features of the Ocaml
compiler, discussed by their implementers in these Github Pull Requests.

- Add compiler support for raw pointers
- Make process creation robust against duplicate descriptors
- Fix PR6638: "unused open" warning was incorrectly suppressed by "open!"
- Branchless computation of the integer absolute value
- Support inherited field in object type expression
- injective mapping between identifiers and printed names
- Universal do..done
- Remove global variables in hash.c

Other OCaml News

From the ocamlcore planet blog:
Here are links from many OCaml blogs aggregated at OCaml Planet,

Polynomials over rings

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.

Alan Schmitt