Previous week Up Next week


Here is the latest Caml Weekly News, for the week of February 05 to 12, 2013.

  1. OCaml Platform - Mailing List
  2. Memoize GADT
  3. ocp-indent beta release
  4. Core Suite 109.08.00 released
  5. OCaml Labs Monthly Update
  6. OMonad 0.2
  7. OCaml tests on Travis CI
  8. geany as an ocaml ide
  9. ReactiveML 1.08.04
  10. Other Caml News

OCaml Platform - Mailing List


Amir Chaudhry announced:
As some of you may be aware from the Consortium meeting, there's an
ongoing project to create an OCaml Platform. The Platform will combine
the core OCaml compiler distribution from INRIA with a comprehensive,
coherent set of libraries, tools, documentation, and other resources.
For example, the OPAM package manager will play a central role in both
packaging and distribution, as well as supporting continuous
integration testing.

This email is to let you know that we've set up a mailing list to
discuss the Platform (platform <at>, and those who
are interested can follow the day-to-day discussions there [1]. Any
important announcements, including releases, would also be copied to
the caml-list when appropriate, so you don't need to join if you only
want updates.

Best wishes,


Memoize GADT


Christophe Papazian asked and Alain Frisch replied:
> this must be a very basic question for some of you, sorry for the inconvenience :
> When I have function "f" of type (a -> b), I can easily add a layer to
> that function to memoize the result by using a (a,b) Hashtbl.t to
> store the results of the expensive to compute "f".
> let mf = let e = Hashtbl.create 0 in ( fun x -> try Hashtbl.find e x with Not_found -> let res = f x in Hashtbl.add e
> x res; res )
> But now, I have a function "g" 
> 	let g (type a) : a gadt -> a = ....
> And If I apply the same method, type a becomes weak (_'a).
> Is there something simple to memoize that function as easy as the
> previous example and keep its polymorphism ? I think not, but I hope
> to be wrong.

We have encountered exactly the same problem recently.  A slightly more 
general version of your question is how to memoize a function of type

   'a t -> 'a s

for two type parametrized constructors t and s (and similarly with 
higher arities).  We want an hash table which can hold key/value 
bindings ('a t * 'a s) for any 'a.  The equality of keys must be such 
that when (key1 : 'a t) is equal to (key2 : 'b t), we can deduce that 'a 
and 'b are the same type (i.e. the value must hold enough information to 
deduce the type from the content), which guarantees that 'a s and 'b s 
are also the same type (and so the existing value associated to key1 can 
be returned for key2).  This assumption often holds when 'a t is a GADT 
representing "expressions which evaluate to values of type 'a".

Our solution (implemented by my colleague Sebastien, in Cc:) has been to 
create a functor with the following signature:

module type ParametricType = sig
   type 'a t

module ParametricEquality : sig
   type (_, _) t =
     | Eq: ('a, 'a) t
     | Ne: ('a, 'b) t

module type ParametricHashedType = sig
   type 'a t
   val equal: 'a t -> 'b t -> ('a, 'b) ParametricEquality.t
   val hash: 'a t -> int

module ParametricHashtbl : sig
   module type S = sig
     type 'a key
     type 'a value
     type binding = Binding: 'a key * 'a value -> binding
     type t
     val create: int -> t
     val clear: t -> unit
     val reset: t -> unit
     val copy: t -> t
     val add: t -> 'a key -> 'a value -> unit
     val remove: t -> 'a key -> unit
     val find: t -> 'a key -> 'a value
     val find_all: t -> 'a key -> 'a value list
     val replace: t -> 'a key -> 'a value -> unit
     val mem: t -> 'a key -> bool
     val length: t -> int
     val iter: (binding -> unit) -> t -> unit
     val fold: (binding -> 'a -> 'a) -> t -> 'a -> 'a
   module Make(X:ParametricHashedType)(Y:ParametricType): S with type 'a 
key = 'a X.t and type 'a value = 'a Y.t

Note that the first input of the function (ParametricHashedTyped) looks 
like the standard argument to Hashtbl.Make, except that the equality 
function returns a dynamic witness of equality between 'a and 'b in case 
of equality between two values of types 'a t and 'b t.  This is 
implemented using a GADT.  We also use a GADT to introduce an 
existential on 'a for key/value pairs of type ('a t * 'a s) to be used 
for iterators (iter/fold).  Instead we could have defined those 
iterators as taking a polymorphic function as argument (through 
polymorphic methods or record fields, or with a first-class module), but 
they would have been more heavy to use on the call site (although this 
would avoid the allocation of the Binding constructor).

On the implementation side, there are three choices:

  - Create a type-safe implementation by instantiating Hashtbl, and 
store values which keep a copy of the key, with an existential both on 
keys and on values.  This requires extra comparisons and boxing. (Good 
exercise left to the reader!)

  - Copy and adapt the implementation of Hashtbl, which can avoid some 
of the extra comparisons. (Painful!)

  - The quicker way (and the one we have chosen for now) is to 
instantiate Hashtbl on type Obj.t for keys and values, and using unsafe 
operations (Obj.magic) to cast its result to the signature above.  I 
don't think it is good style to share here code using Obj.magic, so I 
will refrain from doing so :)

We have done the same for Set, Map, association lists and Weak (for 
such, I believe, the unsafe implementation is the only choice, because 
if we wrap the values with freshly allocated existential constructors, 
they can immediately be garbage-collected).

It would probably make sense to provide such functors as part of the stdlib.

ocp-indent beta release


Louis Gesbert announced:
OCamlPro is proud to announce the beta-release of ocp-indent.

Ocp-indent is a simple tool, entirely written in OCaml, which sole purpose is to
indent OCaml code. It can plug-in seamlessly into emacs' tuareg mode, or be run
from vim.

You can try it now with:

$ opam install ocp-indent

$ INSTDIR="$(opam config var prefix)/share/typerex/ocp-indent"

$ echo '(load-file "'"$INSTDIR/ocp-indent.el"'")' >>~/.emacs

$ echo 'autocmd FileType ocaml source '"$INSTDIR"'/ocp-indent.vim' >>~/.vimrc

Or check it out at

It presents many improvements over the tuareg indentation engine, a much better
understanding of the syntax, linear complexity, specific handling for many
cases. Also, it was intentionally provided with much less customisation options.

Feel free to submit any code snippet that is not indented to your taste, to help
us improve ocp-indent further.

Some comparison with tuareg on a few big OCaml projects can be seen at
Daniel Bünzli asked and Louis Gesbert replied:
> To which extents does it support the programming guidelines [1] ?
> Best,
> Daniel
> [1]

They should be fully supported -- please report a bug if you find any 

One exception is that we indent match-cases if the match doesn't start the line, 
not just when it is after a let:

let x =
  y + match _ with
    | _ -> ...

this gives more readability IMHO
Didier Remy asked and Louis Gesbert replied:
> Why is the choice of tuareg-mode wired-in?
> Is is possible to use ocp-indent on top of the default caml-mode?

Hmm, good remark, there is no real reason for that except that we use tuareg-
mode. I'll see how to remove this dependency from our emacs script.

Core Suite 109.08.00 released


Jeremie Dimino announced:
Another email to announce the 109.08.00 release of the Core
suite. Amongst other things this new release includes the patdiff tool
(which we used to distribute in the past); a diff-like program trying
to improve the output.  You can see an example here:

Files and documentation are available on our website and all packages
are in opam:

This release also fixes a few build issues with OSX.

Full changelog since 109.07.00:

- Async_extra:
  - Added module `Async.Command`
    This is `Core.Command` with additional async functions.  In particular
    it contains a function `async_basic` that is exactly the same as
    `Core.Command.basic`, except that the function it wraps returns
    `unit Deferred.t`, instead of `unit`.  `async_basic` will also start the
    async scheduler before the wrapped function is run, and will stop the
    scheduler when the wrapped function returns.
- Async_unix:
  - Added module `Async.Process`
    This is a new module for creating and dealing with child processes.
  - For ``, replaced the `temp_prefix` argument with `temp_file`.
  - Added `Ivar.invariant` function.
  - Added value `Scheduler.fold_fields`
    This lets one fold over the fields in the scheduler, eliminates an
    annoying place in catalog browser that reached into the internals of
    async to compute the sizes of the scheduler fields
- Core:
  - Cleaned up and updated the `README`.
  - Changed executables to enable backtraces if `OCAMLRUNPARAM` is not set.
  - Changed `Command` so that executables show build info and version info
    This happens when an executatble is called as:

      foo.exe version

    Before this change, rather than display build info, executables
    would display the not-so-helpful:

    (no option given - printing version)
  - Added back `Float` rounding functions with a hardcoded direction.
  - Exposed `with bin_io` and `with compare` for the =sexp_bool= type.
  - Added value `Core.Never_returns.sexp_of_t`.
  - Added values `Or_error.tag{,_arg}`
    These are analogous to `Error` functions of the same name.
  - Added functor `Sexpable.Of_sexpable`
    This is for serializing values of one type as though it were some
    other isomorphic type.
  - Added module `Backtrace.Exn`
    This exposes OCaml stdlib's `Printexc` functions for backtraces.
  - Added module `Flags`
    This implements Unix-style sets of flags that are represented as an
    `int` with various bits set, one bit for each flag, e.g.,
  - Added module `Uuid`
    This module implements universally unique identifiers based on version
    3 of the UUID specification.  It used to be in `Core_extended=`
  - Added module `Type_equal`, which defines the "equality" GADT.
- Type_conv:
  - Fixed type_conv to stop dropping parens in arguments such as:

      type t = {
        a : int with default(1), sexp_drop_if(fun x -> (x + 1) * 2 = 4)
      } with sexp

If you don't see the changes you submitted they are on their way for
the next release.
Gabriel Scherer asked and Jeremie Dimino replied:
> Patdiff looks nice. Could you comment on its portability? I glanced at
> the code and I spotted some possibly unixy things (eg. "/dev/null").
> In which environments is it expected to work (possibly with degraded
> options)?

It has been tested on Linux and OSX. Right now there might already be
issues with compiling Core in other environments, so I wouldn't be
very confident about portability. For example I tested this week on
FreeBSD and the C stubs failed to build, but it should be easy to fix.
We'll try to improve this for future releases. Windows support should
be possible too with more work.

OCaml Labs Monthly Update


Amir Chaudhry announced:
The monthly update on the OCaml Labs work is now posted on the website.
You can find it at:

OMonad 0.2


Wojciech Meyer announced:
OMonad 0.2 is out! Mostly thanks to the contributions by Jeremy Yallop!

This is a new release of -ppx based syntax extension for monadic
programming that brings to you the following new features:

- generalised handling of patterns on the left side of monadic assignment
- backtracking via fail function
- rich set of examples, including advanced examples and mini parsing
  combinator library

It's worth to note that I perceive this release as the first stable
release, however it requires the current trunk compiler, therefore
version 1.0.0 will follow up after the official compiler release.

Here is an example how to use omonad with OASIS, usually these three
lines are enough:

  BuildDepends:     compiler-libs, compiler-libs.common
  ByteOpt+:         -ppx ppx_monad
  NativeOpt+:       -ppx ppx_monad

Github repository with issue tracking:


However, the preferred way to install omonad now is:

    $ opam update
    $ opam install omonad

this is already available in the git OPAM repository.

OCaml tests on Travis CI


Mike Lin announced:
I've hacked together a way to run the tests for my OCaml projects on
Travis CI, a free service for continuous integration on public GitHub
projects. Hope someone may find this useful.

geany as an ocaml ide


Martin DeMello asked and Ashish Agarwal replied:
> I spent some time last night going through all the "what is a good
> (beginner's) ide for ocaml?" threads I could find online, and trying
> out the various options suggested. I ruled out the following:
> * vim, emacs and eclipse (not beginner-friendly; people who want to
> use them will know how to do it)
> * anything that did not provide a binary install for Windows and OSX,
> and wasn't a simple configure/make/make install on linux
> * anything that needed fiddling with config files just to install it
> * anything that needed the OCaml sources to be independently present
> and configured (!)
> * anything that was abandoned, or didn't seem to support OCaml 4
> I was left with Geany and Komodo Edit as possibilities, and Geany won
> out by letting me open up a file and immediately being able to
> find and run the OCaml compiler. At least on Linux, it was a perfect
> beginner-friendly experience.
> So what do people think about officially promoting Geany as
> the answer to "I'm learning OCaml; what is a good IDE?"? I'd be happy
> to write up a page on it and contribute it.

This page [1] needs some help and is probably a good place for
discussion about IDEs. Please add any discussion you'd like and we'll
merge it. Given your list below, maybe you want to make a table of
features with a checkmark for each IDE having that feature (but that
could be hard to maintain, so plain prose might be better).

Louis Gesbert also replied:
OCaml is definitely lacking in this area; I am at the moment working precisely 
on solving this issue, with a dedicated Gtk editor that runs on Linux, OSX and 
Windows. It is pretty basic at the moment but already has code edition and 
working toplevel interaction (no compilation or project yet).

Release is intended in a few months from now, with sufficient features for 
beginners and students. If successful, it will then be extended to handle 
bigger projects (multi-file, build system integration, etc.).

Until then, you may see the project's github page at (name temporary)
Gabriel Scherer then said and Fabrice Le Fessant replied:
> I must say I'm a bit dubious of dedicated editors: people prefer to
> use the tools they're familiar with from other languages, and I'm not
> really sure what the added value of a different tool would be. There
> have been attempts to write editors for OCaml (Cameleon{,2}, zed (
> )...), so far none of them really gained
> traction.
> Volunteers work on whatever they fancy and I prefer not to interfere
> negatively -- though it's unclear in this case whether this is a
> personal side-project or an OCamlPro project. Moreover, all these
> efforts have led to interesting byproducts: various libraries from
> Cameleon (eg. ocaml-rss ) and zed (
> and in particular the nice toplevel utop
> ).
> That said, I would still feel more enthusiastic about a project that
> can be used with other tools people use ( this is a good property of
> ocp-indent for example ), or directly improving OCaml support about
> tools that already have a user base : syntax highlighting libraries
> for various editors, etc. For example, Online Client-side
> Javascript-implemented In-the-cloud programming editors are all the
> rage now, they use a relatively small number of popular Javascript
> edition engines under the hood, is there work to do to make sure OCaml
> a first-class citizen there?

The goal of this editor is not to replace Emacs or VI, but to be part 
of a minimal distribution under Windows (by OCamlPro): the idea is that 
Windows users downloading OCaml should be able to start writing a simple 
OCaml program without installing anything else. Of course, under 
Linux/Mac OS X, or for bigger projects, they would be advised to use 
more powerful editors (Emacs, Vim, Notepad++, etc.).

Moreover, the two paradigms are not incompatible: you can imagine two 
versions of the "editor", one version with an interface (GTK or 
whatever) to interact with beginners, another version with a 
argument/text interface, to interact with other editors, both providing 
the same set of functionalities (indentation, coloring, documentation, 
code navigation, etc.) through the same set of libraries, and why not a 
Javascript version through js_of_ocaml...
Gabriel Scherer then replied and Fabrice Le Fessant said:
> The OCaml installer for windows (
> ) optionally downloads and
> install Emacs, configured for OCaml use. Couldn't the same approach be
> used to install Geany (or whatever modern-beginner-friendly existing
> editor that works on Windows) on end-user systems?

We are all using different editors, and sometimes, we are even using the 
same editor with different OCaml modes. The point is not to choose the 
editor beginners are going to use in the next 20 years, but to provide a 
minimal environment for beginners with OCaml.

Actually, many programmers use an editor specific to their language 
(Eclipse for Java, Charm for Python, etc.), because they often provide a 
better environment for that language than generic editors.

We decided to implement a new editor because we wanted to design the 
basic building blocks both for this simple editor, and to be useful to 
improve existing editors (Emacs, Vim, etc.).

ReactiveML 1.08.04


Louis Mandel announced:
We are happy to announce the new release of ReactiveML
( with its online toplevel

ReactiveML is a language similar to OCaml extended with a built-in
notion of parallel composition. It is based on the reactive
synchronous model, a kind of cooperative multithreading with a global
notion of time.

The language is well suited to program applications with a lot of
parallel processes which communicate and synchronize a lot such as
video games or simulation problems.

ReactiveML is compiled into plain OCaml code and thus can link or be
linked to any OCaml code.

This new version includes in particular:
- an online toplevel (thanks to js_of_ocaml, tryocaml and Mehdi
  Dogguy) with an interactive tutorial
- a new static analysis which checks that programs are cooperative
- a version of ocamlbuild dedicated to ReactiveML: rmlbuild

Other Caml News

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


First release of PPrint:

[ANN] ocaml-vclock - 0.0.0:

More static analysis with CIL:

Syntactic Meta-Programming in OCaml (II):

OCaml EFL:

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