Previous week Up Next week


Here is the latest OCaml Weekly News, for the week of January 06 to 13, 2015.

  1. Detecting dead code, discovering a project's structure...
  2. ocaml-imap.1.0
  3. llpp v21
  4. simplified BER MetaOCaml N102, for OCaml 4.02.1
  5. Static linking of ppx for iocamljs notebooks
  6. opam-installext
  7. Other OCaml News

Detecting dead code, discovering a project's structure...


Sébastien Hinderer asked and Stéphane Glondu replied:
> Are there tools / techniques one could use to make it easier to
> discover / explore the source code of a big OCaml project?
> In particular,  are there any tools available to help finding dead code
> or coe that may need some refactoring?
> Many thanks for any suggestion.

One suggestion:
Goswin von Brederlow then said and Ashish Agarwal replied:
> That looks cool. But that still needs a lot of manual filtering to get
> results, e.g. to find an unused type or function specified in the
> input signature for a functor.
> It could be nice for ocaml to have warnings for this directly. E.g.:
> module type M = ssig type t type s val x : int end
> moduel F(M : M) = struct type t = M.t end
> Warning: unused value x in signature M for functor F
> Warning: unused type s in signature M for functor F
> Similar for types / values defined but not used in .ml files that do
> not appear in the .mli file.

Maybe Pfff:
Jeremy Yallop also replied to Goswin:
> Similar for types / values defined but not used in .ml files that do
> not appear in the .mli file.

OCaml can warn for these already:

  $ cat unused.mli
  type t
  val x : t

  $ cat
  type t = int
  type s = int
  let x = 3
  let y = 4

  $ ocamlc -w A unused.mli
  File "", line 2, characters 5-12:
  Warning 34: unused type s.
  File "", line 4, characters 4-5:
  Warning 32: unused value y.



Nicolas Ojeda Bar announced:
I am pleased to announce the first formal release of ocaml-imap (opam
package: imap), a library to encode and decode the full (client-side)
IMAP4rev1 protocol.  It is fairly low-level in the sense that it does
not keep track of all the state that is needed to make a useful IMAP
client.  Instead it is meant to serve as an intermediate layer on top
of which higher level abstractions can be built.


It is completely independent of any particular buffering and/or IO
mechanism, and its design draws heavily on D. Buenzli's libraries such
as `xmlm`, `jsonm`, `uutf`, etc.

The library consists of a single module and is thoroughly documented
(docs are online at  I encourage
anyone interested to look at the documentation, especially at the
example code to get a feel for the library.

I have been hacking away at this library on and off for the last 6
months, but was not happy with the end result so far.  But recently I
carefully studied the above mentioned libraries, and inspired by them
I decided to rewrite it once again.  I am now happy with the overall
design, but some bugs may be lurking due to the freshness of the code.
If you do come across any bugs please report them and they will be
promptly looked at.

llpp v21


av1474 announced:
New version of llpp (tagged v21) is now available at


llpp a graphical PDF viewer which aims to superficially resemble

* Bugfixes
* Basic support to view text annotation (handy to read those
  margin notes in ARMARMv8)
* Can be built against OPAM (sh -O)
* Shell completions (bash/zsh) (contributed by Mark Oteiza)
* Compatibility with OCaml 4.02.x
* XKB compatibility (setxkbmap specific keyboard layout switching
  is now possible) [1]
* It should be possible to build things with either shake or ninja

[1] That said maybe things have regressed (AltGr things for instance),
    keyboard handling in X is complicated. But at least following works:
    setxkbmap -layout "us,ru"
    setxkbmap -option "grp:caps_toggle,grp_led:scroll

simplified BER MetaOCaml N102, for OCaml 4.02.1


oleg announced:
BER MetaOCaml is a strict superset of OCaml, adding operations to
construct and run typed code values. BER MetaOCaml N102 is the new
version, which is source _and_ binary compatible with OCaml
4.02.1. That is, staging-annotation-free BER MetaOCaml is identical to
OCaml; BER MetaOCaml can link to any OCaml-compiled library (and
vice versa); findlib and other tools can be used with BER MetaOCaml as
they are, in their binary form.

On the surface, BER N102 has hardly changed from the earlier BER N101.
All BER N101 code should work with the new version as it was. The
users may however notice better printing: of code, error messages and
cross-stage-persistent values. The implementation however has changed
quite a bit, extensively relying on attributes and bringing MetaOCaml
very close to OCaml. It is now a distinct possibility that -- with
small hooks that may be provided in the future OCaml versions --
MetaOCaml becomes just a regular library or a plug-in, rather being a
fork. (Please see below for details.)

The staging annotations are: 
    bracket: .< e >.  to delay computation (to the future stage)
    escape:  .~ e     to perform a computation e and splice-in the result
    run:     !. e     to run a future-stage computation, or code, now

A special type constructor, called 'code' builds the type of
future-stage computations, or code expressions:
    # .< 2 + 4 >.;;
    - : int code = .<2 + 4>. 
For more details,

BER MetaOCaml N102 is available:

-- as a set of patches to the OCaml 4.02.1 distribution.
See the INSTALL document in that archive. You need the source
distribution of OCaml 4.02.1, see the following URL for details.

-- as a GIT bundle containing the changes relative to OCaml 4.02.1
First, you have to obtain the base
       git clone -b 4.02.1 ometa4
and then apply the bundle.

The older, N101 version, is available via OPAM. The new version will
come to OPAM, hopefully soon.

Although on the surface BER N102 is almost the same as the earlier
version, internally it is quite different. To give the idea of the
difference, it is instructive to compare the amount of changes BER
MetaOCaml makes to the OCaml distribution. The old BER N102 modified
32 OCaml files. The new BER N102 modifies only 7 (that number could be
further reduced to only 2; the only file with nontrivial modifications
is The patch size was 49729 bytes before and 34066 bytes

The principal change is the extensive use of attributes, the new
feature of OCaml 4.02. Staging annotations -- brackets, escapes and
CSP -- are now really annotations: attributes on the Parsetree and
Typedtree. MetaOCaml also uses a Typedtree attribute to mark
non-expansive nodes (the non-expansiveness check is performed before
the bracket-translation but is used only after). An attribute on
value_description tells the staging level of the value.

There is no longer a separate Typedtree traversal pass, after the type
checking, to translate brackets and escapes. That means that for
staging-annotation-free code, MetaOCaml has no substantial overhead.
BER N102 has started on revamping cross-stage-persistence; quite a few
CSP have become printable and, mainly, serializable. Non-serializable
CSP were the only impediment to native MetaOCaml.

For more explanations, please see
as well as ChangeLog and NOTES.txt in the BER MetaOCaml distribution.

Hopefully the release of BER MetaOCaml N102 would further stimulate
using and researching typed meta-programming -- and perhaps merging
of MetaOCaml into the mainstream OCaml.
Jeremy Yallop added:
BER MetaOCaml N102 is now also available via OPAM and can be installed
as follows:

   opam update
   opam switch 4.02.1+BER
   eval `opam config env`

Static linking of ppx for iocamljs notebooks


Andy Ray asked and Peter Zotov replied:
> Is it possible to statically link and initialise a ppx filter before
> an OCaml top level runs?  This is needed for IOCaml in it's javascript
> variant.
> Also, is there a general set of files that should be installed in
> order for ppx to work for us static linker types?

Currently, ppx in the compiler is hardcoded to invoke external
processes, see Pparse.apply_rewriter. However, it is possible
to work around that by overriding:
  * Ast_mapper.register_function, to remember the mapper
  * and Toploop.preprocess_phrase, to apply the mapper
    to the incoming phrase.



Deep in an unrelated thread, Kenneth Adam Miller said and Anil Madhavapeddy replied:
> The only thing I think the ocaml environment is missing is a static
> check of the surrounding environment for the tools that will be
> used, for use in opam. That way, when stuff builds, you get told all
> the dependencies instead of doing iterations of finding each missing
> thing by hand.

There's an OPAM plugin that the automated tests use that you may be
interested in trying out.

Install it with:

    opam install opam-installext

Then, if you have `sudo` configured correct you can just do:

    opam installext <pkg1> <pkg2> ...

It will query the `depexts` field for each package which contains
OS-specific external dependencies.

It's still not particularly well integrated into OPAM as it's
external, but full support is in the works so that a plugin won't be
needed in future revisions of OPAM.

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

Towards a governance framework for

About unboxed float arrays:

Full Time: Software Developer (Functional Programming) at Jane Street in New York, NY; London, UK; Hong Kong:

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