Previous week Up Next week


Here is the latest OCaml Weekly News, for the week of October 14 to 21, 2014.

  1. OCaml 4.02.1
  2. uproplib
  3. findlib-1.5.4
  4. Beginner OCaml Books
  5. Jane Street is hiring interns
  6. Dimensional Analysis question
  7. opam-android, a modern Android cross-toolchain
  8. exn-source - exception backtraces with source code printing
  9. utop 1.16
  10. slacko 0.10.0
  11. First class modules sub-typing
  12. Release 0.8.0 of Zenon
  13. Other OCaml News

OCaml 4.02.1


Damien Doligez announced:
We have the pleasure of announcing the release of OCaml version
4.02.1. This is all about speed: not only this release fixes a large
slowdown in the compiler, but today is also the anniversary of the
first time a man broke the sound barrier with an airplane.

This is mainly a bug-fix release, see the list of changes below.

It is available here: < >

This is released as source on our web site, but the OPAM switch will
be available very soon (in a few minutes).

Happy hacking,

-- Damien Doligez for the OCaml team.

OCaml 4.02.1:
(Changes that can break existing programs are marked with a "*")

Standard library:
* Add optional argument ?limit to Arg.align.

- PR#4099: Bug in Makefile.nt: won't stop on error
  (George Necula)
- PR#6181: Improve MSVC build
  (Chen Gang)
- PR#6207: Configure doesn't detect features correctly on Haiku
  (Jessica Hamilton)
- PR#6466: Non-exhaustive matching warning message for open types is confusing
  (Peter Zotov)
- PR#6529: fix quadratic-time algorithm in Consistbl.extract.
  (Xavier Leroy, Alain Frisch, relase-worthy report by Jacques-Pascal Deplaix)
- PR#6530: Add stack overflow handling for native code (OpenBSD i386 and amd64)
  (Cristopher Zimmermann)
- PR#6533: broken semantics of %(%) when substitued by a box
  (Benoît Vaugon, report by Boris Yakobowski)
- PR#6534: legacy support for %.10s
  (Benoît Vaugon, Gabriel Scherer, report by Nick Chapman)
- PR#6536: better documentation of flag # in format strings
  (Damien Doligez, report by Nick Chapman)
- PR#6544: Bytes and CamlinternalFormat missing from threads stdlib.cma
  (Christopher Zimmermann)
- PR#6546: -dsource omits parens for `List ((`String "A")::[]) in patterns
  (Gabriel Scherer, report by Peter Zotov)
- PR#6547: __MODULE__ aborts the compiler if the module name cannot be inferred
  (Jacques Garrigue, report by Kaustuv Chaudhuri)
- PR#6549: Debug section is sometimes not readable when using -pack
  (Hugo Heuzard, review by Gabriel Scherer)
- PR#6553: Missing command line options for ocamldoc
  (Maxence Guesdon)
- PR#6554: fix race condition when retrieving backtraces
  (Jérémie Dimino, Mark Shinwell).
- PR#6557: String.sub throws Invalid_argument("Bytes.sub")
  (Damien Doligez, report by Oliver Bandel)
- PR#6562: Fix ocamldebug module source lookup
  (Leo White)
- PR#6563: Inclusion of packs failing to run module initializers
  (Jacques Garrigue, report by Mark Shinwell)
- PR#6564: infinite loop in Mtype.remove_aliases
  (Jacques Garrigue, report by Mark Shinwell)
- PR#6565: compilation fails with Env.Error(_)
  (Jacques Garrigue and Mark Shinwell)
- PR#6566: -short-paths and signature inclusion errors
  (Jacques Garrigue, report by Mark Shinwell)
- PR#6572: Fatal error with recursive modules
  (Jacques Garrigue, report by Quentin Stievenart)
- PR#6578: Recursive module containing alias causes Segmentation fault
  (Jacques Garrigue)
- PR#6581: Some bugs in generative functors
  (Jacques Garrigue, report by Mark Shinwell)
- PR#6584: ocamldep support for "-open M"
  (Gabriel Scherer, review by Damien Doligez, report by Hezekiah M. Carty)
- PR#6588: Code generation errors for ARM
  (Mark Shinwell, Xavier Leroy)
- PR#6590: Improve Windows (MSVC and mingw) build
  (Chen Gang)
- PR#6599: ocamlbuild: add -bin-annot when using -pack
  (Christopher Zimmermann)
- PR#6602: Fatal error when tracing a function with abstract type
  (Jacques Garrigue, report by Hugo Herbelin)
- ocamlbuild: add an -ocamlmklib option to change the ocamlmklib command
  (Jérôme Vouillon)
Anil Madhavapeddy then added:
There are now also updated binary packages for OCaml 4.02.1, Camlp4 and OPAM 
available for Debian, Ubuntu, Fedora, RHEL and CentOS, from:

Since ARM is a little slower than the speed of sound, those on embedded 
devices may also find the armhf binary packages useful in the Launchpad PPAs. 
There are specific PPAs for combinations of OCaml and OPAM at:

Instructions on how to install these binary packages on various distributions 
are available from:

The OPAM Travis tests (which uses the Ubuntu Launchpad PPAs above) will only 
be testing 4.02.1 from now on for the 4.02.x test matrix. Please let me know 
if you specifically need 4.02.0 tested for some reason. 



Yoriyuki Yamagata announced:
I am pleased to announce "uproplib", a library which provides access
to Unicode Character Database (UCD).

UCD is compiled into the binary of the library itself, so, unlike
camomile,  you do not need to specify the location of data files.  The
size of the library is about 3M bytes on my Mac, but since each
property is packaged as a separate module, you only need to link the
properties which you need.  uproplib contains all UCD properties
except Unihan properties.

To compile uproplib, you need ucorelib and Daniel Bünzli 's uucd, in
addition to standard ocaml and Unix tools.

This is very early alpha release.  There is no documentation, no opam
package, and even no test :-)



Gerd Stolpmann announced:
a new minor version has been released. There is a new ppxopt META
variable allowing to pass options to ppx rewriters (for toploop use,
ocaml-4.02.1 is required). This variable allows to set options for
required ppx packages (e.g. ppxopt="pkg1,foo pkg2,bar" passes option foo
to the ppx rewriter in package pkg1, and bar to the ppx rewriter defined
in pkg2).

Also, a new environment variable FINDLIB_TOOLCHAIN was added. Both
changes were developed by Peter Zotov (thanks for this).

As always, links for download can be found here:

Beginner OCaml Books


Roelof Wobben asked and Stefan Schmiedl replied:
> What is a good online book for a beginner to learn Ocaml with a lot of 
> exercises.

I recommend John Whitington's books, available as DRM-free PDF
at (not free, but worth every penny).
Malcolm Matalka also replied:
Mario Alvarez Picallo also replied:
John Whitington's books are excellent resources for beginners. You
might also want to consider Real World OCaml, which is freely
available at
Francois Berenger also replied:
There are also some simple online exercises:

Jane Street is hiring interns


Yaron Minsky announced:
Jane Street is actively hiring summer interns for our offices in New
York, London and Hong Kong.

Interning at Jane Street is a great learning experience.  If you're
interested in seeing how functional programming is applied to real
world problems at big scale, there's no better place.

Look here

to get a sense of the kinds of projects summer interns do.  As is
reflected there, many of our intern projects make their way out as
open-source projects.  Interns also learn about Jane Street's trading
business through lectures and interactive training sessions.  Plus,
there are a lot of fun social activities throughout the summer.

Feel free to redistribute this to any students you think might be
interested.  And if you're interested directly, you can apply here:

And as usual, we're also hiring developers for fulltime positions in
NYC, Hong Kong and London.

Dimensional Analysis question


Shayne Fletcher asked:
In 1994, Barton and Nackman in their book 'Scientific Engineering in
C++' [1] demonstrated how one could encode the rules of Dimensional
Analysis [2] into the C++ type system enabling compile-time checking
(no runtime-cost) of the plausibility (at least up to the dimensional
correctness) of computations.

In 2004, Abrahams & Gurtovy in 'C++ Template Metaprogramming' [3]
showed the Barton Nackman technique to be elegantly implementable
using compile time type sequences encoding integer constants. At the
end of this post, I provide a complete listing of their example
program [4].

The key properties of the system (as I see it) are:
- Encoding of integers as types; 
- Compile time manipulation of sequences of these integer encodings
to deduce/produce new derived types.

Now, it is not immediately obvious to me how to approach this problem
in OCaml. It irks me some that I can't immediately produce a yet more
elegant OCaml program for this problem and leaves me feeling like C++
has "got something over on us" here ;)

My question therefore is: Does anyone have suggestions/pointers
on how to approach automatic dimensional analysis via the OCaml type


Shayne Fletcher

[1] John J. Barton and Lee R. Nackman. Scientific and Engineering C++:
an Introduction with Advanced Techniques and Examples. Reading,
MA: Addison Wesley. ISBN 0-201-53393-6. 1994.

[2] Wikipedia

[3] David Abrahams and Aleksey Gurtovy C++ Template Metaprogramming:
Concepts, Tools, and Techniques from Boost and Beyond (C++ in
Depth Series), Addison-Wesley Professional. ISBN:0321227255. 2004.

[4] Code listing: see
Roberto Di Cosmo replied:
you might have a look at the thread answering a similar question
I asked last june on the list, here:

Notice that the very first viable experiment of a variant of CamlLight
with full dimension types (non encodings) was announced by Bruno Blanchet back in 1995

opam-android, a modern Android cross-toolchain


Peter Zotov announced:
I'm glad to announce opam-android, a cross-toolchain for Android
based on OCaml 4.02.1. The goals of this port was to minimize
the changes to the OCaml compiler, to simplify porting packages
as much as possible, to support compile-time components like
ppx rewriters or cstubs, and to make using it as simple as possible.

I believe I have achieved these goals. In particular, I want
to highlight that both bytecode and native code compiling works,
-output-obj works and can be used to emit .o and .so files,
and using the toolchain is as simple as passing -toolchain android
to your ocamlfind invocation (or even setting the OCAMLFIND_TOOLCHAIN
environment variable).

For further details and installation instructions, please refer to
the GitHub project page:

exn-source - exception backtraces with source code printing


John Whitington announced:
OCaml 4.02 has new facilities for installing a new backtrace handler,
and processing the back trace symbolically. As a little proof of
concept, I've built a package which you can add to any project to get
backtrace with source code printed and highlighted:

Here's the start of a backtrace:

By default, it prints five lines either side, and looks the current
directory for source code. But as one can see from the screenshot, one
can add /usr/local/lib/ocaml to get stdlib source and so on...

It's somewhat difficult to test this kind of thing (we can't use
exceptions at all inside a backtrace handler, for example), so I'm
appealing for help. Attach exn-source to your code and let me know how
you get on...
Gabriel Scherer replied:
That looks like a nice project ! Another trick I use personally is to
run the faulting program from inside Emacs's compile-mode (using
"build && run" instead of just "build" as a compilatoin command), and
piggy-back on its parsing of OCaml error locations to ask Emacs to
drive me around the relevant files.
I'm sure there are scenarios where your simultaneous view of all
fragments at once can be very helpful, and I'm also interested in the
uses of the new backtrace/callstack inspection API.

> (we can't use exceptions at all inside a backtrace handler, for
> example)

I'm a bit surprised by this. Part of the point of reifying traces into
datatypes (raw_backtrace, backtrace_slot) was to make them persistent.
set_uncaught_exception_handler is passed a raw trace that should not
be mutated by raising new exceptions. What breaks if you use
exceptions inside a backtrace handler?
John Whitington then said:
To quote the documentation for set_uncaught_exception_handler: "If fn
raises an exception, it is ignored."

This is a bit ambiguous -- it might mean

a) The uncaught exception handler you register won't get called from
inside itself in the case of an uncaught exception. Nor will any such
exceptions be handled by the standard exception handler; or

b) Exceptions in the handler literally have no effect.

I've done a little test just now, and it seems to be (a), so perhaps
it's just in need of clarification in the documentation.

(It might be nice to have, for development, an option to have the
default exception handler remain active, so it reports any exceptions
escaping from the user-installed exception handler).        
Peter Zotov commented and John Whitington replied:
> Very nice project! However, it looks like the user needs to explicitly
> specify the paths to the sources. I have some code to perform a similar

Yes, except for '.' which is hardcoded. So, in the simplest case, it works.

> task[1]; the paths are actually contained inside the bytecode.
> I think that for native-code you can fetch them in a similar way, though
> it is a little harder to extract the debug info.
> [1]:,
> see di_paths.

Noted. I'd like to add functionality like this. The first thing I'm
going to add is automatic finding of the stdlib, since this just
requires parsing the output of "ocamlc -config".

Unfortunately, I don't believe most OPAM packages install their
source, just the .mli files. I wonder how much extra space installing
source would take on average, and if people think it's worth it, for
this or other reasons.
Peter Zotov then said:
> Noted. I'd like to add functionality like this. The first thing I'm
> going to add is automatic finding of the stdlib, since this just
> requires parsing the output of "ocamlc -config".

I would take this directly from OCaml configuration (module Config,
-package compiler-libs.common). No shelling out needed.

utop 1.16


Peter Zotov announced:
I'm glad to announce utop 1.16. It will be available in OPAM shortly.

1.16 (2014-10-20)

* make camlp4 support optional
* require OCaml 4.01.0 or newer
* implement wrapper for -safe-string

slacko 0.10.0


Marek Kubica announced:
I'd like to announce a new release of Slacko, the OCaml Slack API
binding. This is both an announcement as well as a request for comments
regarding the API.

The homepage is at, the
documentation can be read online at and the tarball as well
as release notes can be found on The
recommended way is to install it from OPAM of course, which already
carries the 0.10.0 release.

I've listened to the suggestions by Malcolm, Gabriel and Jaques as well
as Drup so the methods are not longer "stringly" typed, each function
supports parameters that make more sense, like user/group/channel
types, booleans, integers etc. The results are changed from a huge
monolithic type to individual polymorphic variants composed of smaller

But some questions remain: I have a number of types and conversion
functions (foo_of_string mostly). These can validate the input
(checking if the format is correct or whether the input is not too
long) and most likely should. But what is the preferred OCaml way of
handling failure to convert? I could use exceptions but that seems
kinda type unsafe to me. I could use option types, but that might make
for some clunky conversions. Any ideas?

Also there are errors like `Msg_too_long. I'm currently exposing them,
because the API might throw them. But when doing validation inside my
binding, these errors can't really happen, since I validated
beforehand. I think that these can be filtered out (since the length
limit is static and if it changes, the library can be updated), but if
anyone has a different perspective, please speak up.

Looking forwards to comments!

Oh and I ported from the Camlp4 Lwt macros to PPX. Was super easy and
worked like a charm, zero issues.

First class modules sub-typing


Thomas Braibant asked:
I am slightly puzzled by a type-error related to first class modules.
I am basically defining two types (see full example below)

type t = (module A)
type 'a s = (module A with type I.t = 'a)

and I expect a value of type `'a s` can be coerced to a value of type
t. However, this is obviously not the case because I get the following
error message, and I wonder why.

(* Error: This expression has type a s = (module A with type I.t = a) *)
(*        but an expression was expected of type t = (module A) *)

Is there a common pattern to deal with this situation? Any pointers appreciated.


(* Full example *)

module type IN = sig
  type t
  val of_string : string -> t
  val to_string : t -> string

module type A = sig
  module I : IN
  val v : string

type t = (module A)
type 'a s = (module A with type I.t = 'a)

let test1 : t -> string = fun (module T) -> T.v
(* let test2 : 'a s -> string = fun (module T) -> T.v

   The type of this packed module contains variables:
   'a s
let test3 (type a) : a s -> string = fun (module T) -> T.v
let test4 (type a) : a s -> string = fun t -> test1 t
(* Error: This expression has type a s = (module A with type I.t = a) *)
(*        but an expression was expected of type t = (module A) *)

module A1 : A = struct
  module I : IN = struct
    type t = int
    let of_string = int_of_string
    let to_string = string_of_int
  let v = "A1"

let _ = test1 (module A1) (* OK *)
let _ = test3 (module A1) (* OK *)
Jeremy Yallop replied:
Conversions between first class module types need explicit coercions.
It's sufficient to change your test4 function as follows:

> let test4 (type a) : a s -> string = fun t -> test1 t

   let test4 (type a) : a s -> string = fun t -> test1 (t :> (module A))
He later added:
 or you can, of course, use the alias 't' to coerce:

      let test4 (type a) : a s -> string = fun t -> test1 (t :> t)

Release 0.8.0 of Zenon


François Pessaux announced:
It is my pleasure to announce (for Damien Doligez ^_^) the release of
Zenon, an automatic theorem prover written in OCaml.

Zenon handles first-order logic with equality. Its most important
feature is that it outputs the proofs of the theorems, in
Coq-checkable form.

This is version 0.8.0, available at < > (and
soon at < >) with several issues fixed since
the last release.

Unfortunately, there is no documentation yet, so this is for the
adventurous spirit.

It is released under the New BSD license.

Other OCaml News

From the ocamlcore planet blog:
Thanks to Alp Mestan, we now include in the OCaml Weekly News the links to the
recent posts from the ocamlcore planet blog at


Haskell : A neat trick for GHCi:

OCaml 4.02.1 released:

What the interns have wrought: RPC_parallel and Core_profiler:

TEDx Zeroes:

OCaml Forge maintenance:

Binary distribution with 0install:

Functional Software Engineer at Cake Solutions Ltd (Full-time):


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