Previous week Up Next week


Here is the latest OCaml Weekly News, for the week of January 31 to February 07, 2017.

  1. visitors
  2. Feedback on cmdliner doc language changes
  3. Memory Usage
  4. omake-0.10.2
  5. cppo, ocamlbuild, and dependencies
  6. where are we on the Hoogle for OCaml front?
  7. llpp v26
  8. Research officer in theoretical foundations of cyber security at Swansea University
  9. Ocaml Github Pull Requests
  10. Other OCaml News



Continuing this thread from last week, whitequark said:
I wrote this tool long ago, it's called ppx_import[1]. In fact it motivated
some improvements to the compiler, chiefly the way to extract the set of -I
It's even linked from ppx_deriving README[2].

François Pottier then said, and whitequark replied:
> This is very cool, and I had missed it. Thanks for pointing it out.
> I will refer to it in the visitors documentation.
> By the way, the ppx_deriving README says that ppx_import is useful
> "in the case where no attributes need to be attached",
> but it is more useful than that,
> since the "@with" form actually allows attaching attributes a posteriori.

That paragraph predates [@with]. I've updated it now.
François Pottier then asked and Emilio Jesús Gallego Arias replied:
> Is it possible to use ppx_import to import and copy not just one type
> definition, but a whole family of (possibly mutually recursive) type
> definitions?

whitequark of course will know the exact details, but indeed ppx_import
seems capable to work in your use case, see:
François Pottier then said and whitequark replied:
> Thanks Emilio. This works indeed, but you have to write one line for
> every type that you want to import. When you have 86 mutually
> recursive
> types, that seems silly :-)

Unfortunately Emilio has the shortest implementation that's possible right now.
I think this would be a fairly straightforward addition to ppx_import.
Emilio Jesús Gallego Arias finally said:
In the lines of François suggestion, it would be great if ppx_import
could some kind of "batch" import for modules. Imagine you want to add
show to a whole module, you could do:

[%import: M
  [@attach all [[@deriving show]]]]


module M = [%import M ....]

Another option is to teach deriving about modules:

module M = M
[@@deriving sexp]

but I am not sure what would be the best way to avoid all the
boilerplate I currently have [would had submitted an issue otherwise]

Feedback on cmdliner doc language changes


Daniel Bünzli announced:
The current cmdliner manual doc language is broken beyond hope. The next release
is going to fix that which may break the rendering of some manpages [1]. Your
feedback on the changes and new language definition is welcome:

Discussion can happen here:



[1] I suspect most will not. But if: 

 git grep '\$([ib],[^)]*\$([mt]name)[^)]*)' 

exits with 0 in your project you are affected for sure. Simply replace these
marked up $(b,$(tname)) and $(b,$(mname)) by the variables $(tname) and $(mname)

Memory Usage


Continuing the thread from last week, Alain Frisch said:
If you are only interested in measuring how much a given function allocates, you
can simply call Gc.allocated_bytes before and after.

Otherwise, and in addition to other great suggestions, let me add this one:



Gerd Stolpmann announced:
it is my pleasure to announce omake-0.10.2. This is mainly a bug fix

 - fixing build of omake on bytecode-only system
 - (again) fixing "rm -rf" on Windows
 - omake defaults now to the C compiler used by OCaml
 - building the omake documentation is now optional
   (even if hevea is installed - could be non-working)
 - fix inotify on Linux (for omake -P). Note that it is
   still not working on Mac.
 - fix recognizing case-insensitive filesystems on Mac
 - fix the OCamlPackage macro when a pack is created
   and no pack-level mli file is present
 - omake now ignores the env vars PREFIX, BINDIR and
   LIBDIR at install time

The new homepage is now
See there for all the other links. The opam package will be updated

The old homepage is no longer updated (I don't have
access, and don't know how to take it down).

cppo, ocamlbuild, and dependencies


François Pottier asked and Gabriel Scherer announced:
> I am trying to use cppo and ocamlbuild together.
> Suppose the file contains the line:
>   #include "".
> Then, the build fails. As far as I understand, ocamlbuild is not aware of
> the
> dependency ->, so the source file is not even
> copied to the _build directory.
> I am using the build rules bundled with cppo (in the module
> Ocamlbuild_cppo).
> Shouldn't these build rules be improved so as to perform a genuine
> dependency
> computation? Has anyone run into this issue?

Yes, the cppo ocamlbuild plugin
does not currently perform any kind of dynamic dependency computation.

I think the best way for this to be implemented would be at the level
of cppo, have a kind of -list-includes flag that would run on a
.cppo.* file and return the list of includes. Then you could easily
change the cppo rule to call this first, dynamically build all these
dependencies, and proceed with normal cppo processing. (I believe this
is roughly how `gcc -M` works.)

In the meantime, I implemented an amusing hack at the ocamlbuild level
which is to simply parse the failure message and, if it complains
about a missing file, recursively build that file as a dynamic
dependency. It seems to work.

(The code below is just a change over the main function of cppo's
ocamlbuild plugin. To use it in your program, copy the cppo's
ocamlbuild source in your, replace the relevant
function, and at the end add "let () = dispatch dispatcher" or
whatever dispatch logic you wish.)

let cppo_rules ext =
  let dep   = "%(name).cppo"-.-ext
  and prod1 = "%(name: <*> and not <*.cppo>)"-.-ext
  and prod2 = "%(name: <**/*> and not <**/*.cppo>)"-.-ext in
  let cppo_rule prod env build =
    let dep = env dep in
    let prod = env prod in
    let tags = tags_of_pathname prod ++ "cppo" in
    let cppo = S[A "cppo"; T tags; S [A "-o"; Px prod]; P dep] in
    let rec retry tmp =
      let cppo_to_tmp = S[cppo; Sh "2>"; P tmp ] in
      let cppo_cmd = Command.to_string (Cmd cppo_to_tmp) in
      match Sys.command cppo_cmd with
      | 0 -> Nop
      | _ ->
        let cppo_result = read_file tmp in
        let error = Str.regexp
            {|Error: Cannot find included file "\([^"]*\)"|} in
        (* If we cannot find the dependency,
           or if building the dependency fails,
           we return the original cppo command.

           This will do a bit of useless work but give a better error
           message than having the rule raise an exception here, as it
           will present the failure in terms of the cppo error message
           the user knows about, instead of backtracking in other
           rules. *)
        match Str.search_forward error cppo_result 0 with
        | exception Not_found -> Cmd cppo
        | _pos ->
          let dep = Str.matched_group 1 cppo_result in
          match build [[dep]] with
          | [Outcome.Good _dep] -> retry tmp
          | _ -> Cmd cppo
    with_temp_file "ocamlbuild_cppo" "stderr" retry
  rule ("cppo: *.cppo."-.-ext^" -> *."-.-ext)
    ~dep ~prod:prod1 (cppo_rule prod1);
  rule ("cppo: **/*.cppo."-.-ext^" -> **/*."-.-ext)
    ~dep ~prod:prod2 (cppo_rule prod2)
François Pottier then said and Gabriel Scherer replied:
> Thanks Gabriel for your quick reply.
> This seems amusing indeed, but does not quite work for me. Running
> ocamlbuild
> once fails, complaining that does not exist (whereas exists).
> If I immediately run ocamlbuild again, the build succeeds.
> I think I would prefer to use a slightly less amusing approach and just find
> out, ahead of time, what the dependencies are. In the rule that transforms
> to, could I just read the source file, looking #include
> patterns, and ask that the included files be built first?

Yes, of course, your approach would also work
(`Ocamlbuild_plugin.read_file` is you friend, followed by the parsing
technique of your choice). The only issue is that you may
over-approximate dependencies depending on how closely you approximate
cppo's grammar (and I don't know, maybe there is a way to have
computed inclusion instead of just file path literals?), so this logic
would be easier to implement correctly in cppo itself.

You may find inspiration in the part of the manual that describes how
to write rules with dynamic dependencies (the explained example is the
code of the (.itarget -> .otarget) rule):

where are we on the Hoogle for OCaml front?


François Berenger asked and Jacques Garrigue replied:
> Do we have a hoogle[1] equivalent that is in production for OCaml?
> I mean something that would index all source code available in opam
> and allow queries by type signature or keyword?
> Currently, I use ocp-browser but I still feel like
> it's a temporary and not super efficient measure.
> I don't know how to do query by type signature with it.
> And many packages don't install their doc so you cannot
> see the doc for each function.
> At list for the stdlib it works (inside ocp-browser you type then
> spacebar, for example).
> When I was an Haskell programmer (for two months, a long time ago), I felt
> Hoogle was the biggest productivity enhancer (you don't reinvent
> the wheel, just find which one you need and use it).
> Regards,
> F.
> [1]

For search by type signature you can use Jun Furuse's OCamlOScope:

It also gives documentation when available.

I'm not sure how big the database is.
Daniel Bünzli asked and Hendrik Boom replied:
> I'm a little bit curious. While I can see the benefit of having general full
> text search over value identifiers, type identifier and doc strings I was
> always a little bit dubious about type signature search -- in the end ML types
> for themselves are a rather weak specification language (I'm not talking about
> the invariants you may hide behind those of course).
> So beyond curiosity searches are actually people seriously using this to
> lookup a value they might need ?

Search on parts of the type, even.  It is very useful to find all the 
functions that do anything with values of a particular type in order 
to find out what you can do with it.  As well as how you can produce 
values of that type.
Ivan Gotovchits replied:
Yep, the same as it is done in Coq's search command, where you query all
functions that produce integer

Search (_ -> int)

It is extremely useful in Coq, and should be as well in OCaml. 

For example, when I see, that a function requires a value of type `Uuidm.t`,
then a search for `_ -> Uuidm.t` will reveal all possible ways to create it. (Of
course, I can just go to the mli file, and read it, but this defeats the whole
purpose of searching).
Daniel Bünzli also replied and Ivan Gotovchits said:
> Sure but boolean queries on type identifiers seems enough for this. Of course
> you can always wish to be more precise --- I want this type to appear in that
> position --- but I'm not sure that's an information need users often have.

That's why the search should be up-to some isomorphism, e.g., 

int -> float -> bool

is isomoprhic to

float -> int -> bool

The seach should also work correctly with lots of aliases, since it is usual
when the same type or value in OCaml has mutliple names. The seach should also
ignore parameter names, as this is not what a user can know in advance.
Ivan Gotovchits then added:
This is a link [1] to the underlying theory of type isomorphism search, for
those who are interested:

Daniel Bünzli then said and Ivan Gotovchits replied:
> The papers you mention seem to be about the type ismorophism theory but I can't
> see any that tries to asses end-user information needs and retrieval
> evaluation. I'm not sure you need the full theory to build an effective system
> to support a programmer, e.g. what about the effectiveness of a full type
> isomorphism search vs a bag of type identifiers with functional position model.
> Meaningfully limiting the query power to an IR system is a problem in practice,
> for space, computational and user interface reasons.

Well yes, the theory is not required, but it is better to know one :) I provided
a link mostly because it is a sort of a homepage for type-isomorphic search.
There are links to the CamlLight implementations (yeah the idea was there for
some time) and Haskel. Speaking of modern implementations, Argot [1] is the only
example that comes to mind. It has the isomorphic search and a type manifest
search. The search is implemented mostly in Javascript (generated from OCaml).
(Probably, you heard the story that it is broken and abandoned, and yadda

The digest of the theory, is that we have the following rules:

1. a -> b -> c ~ b -> a -> c
2. a * b -> c ~ a -> b -> c
3. unit -> a ~ a

And by applying these rules recursively we can build a set of types that are
isomorphic to the query (or partition all the types into the isomoprhism

Frédéric Bour then added:
The experimental version of Merlin implements a similar feature (however it
looks only in loaded packages, not the whole opam universe).

It is based on names (normalizing type constructors to resolve aliases), and
uses variance information (types occurring in positive and negative positions)
to guide the search.

The prototype query language looks like "-int +string" for "string of int". You
can see a demo here: .

llpp v26


moosotc announced:
New version of llpp (tagged v26) is now available at:
* (has "tutorial" videos)
* (has a bug tracker)


llpp is a graphical PDF viewer, which aims to superficially resemble

Changes (relative to v25)

* native macOS support (Nicolás Ojeda Bär)
* wrapper-script to reload document on file change (Pascal Wittmann)
* bugfixes

Summary v25..v26
   160	Nicolas Ojeda Bar
     1	Pascal Wittmann
     1	Tobias Kortkamp
    78	malc

Diffstat v25..v26
 .gitignore                 |    5 +-
 .merlin                    |    1 +
 .ocp-indent                |    2 +
 BUILDING                   |   13 +-
 Shakefile.hs               |   13 +-                   |   53 ++-                  |  106 ++---                    |    6 +-
 link.c                     |  185 ++------                    | 1122 ++++++++++++++++++++------------------------
 main_osx.m                 |  906 +++++++++++++++++++++++++++++++++++
 misc/Info.plist            |   53 +++
 misc/completions/   |   19 +-
 misc/dicx                  |    8 +-
 misc/gc.awk                |   23 -
 misc/llpp.desktop          |    4 +-
 misc/llpp.inotify          |   38 ++
 misc/llppac                |   10 +-                  |    0                   |    4 +-                   |   60 ++-
 wsi/osx/             |  318 +++++++++++++ => wsi/x11/   |  132 ++----
 wsi.mli => wsi/x11/wsi.mli |   10 +-
 24 files changed, 2089 insertions(+), 1002 deletions(-)

Research officer in theoretical foundations of cyber security at Swansea University


Markus Roggenbach announced:
Research officer in theoretical foundations of cyber security at Swansea University

Duration: 3 years
Available now
Application deadline: 24.2.17

Within an EPSRC funded project, we have a research position that
offers an opportunity to undertake research in the broad area of
Trust, Identity, Privacy and Security. To this end we want apply
algebra and logic in explorations of topics such as

- security and privacy properties for data sharing; 
- block-chain technologies;
- digital identities;
- authentication and certification.

The position provides an opportunity to enter the important,
developing field of formal methods for cyber security.

We encourage any candidate with experience in

- theory of computation;
- formal methods for software development;
- logic and AI; or
- computer security

to apply for our position. A previous track record in cyber security will be valuable,
however not be necessary.

For informal enquires please contact
Prof John Tucker ( or 
Prof Markus Roggenbach (

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.

- Unix library: better API for "close-on-exec" over file descriptors
- Define Map.update.
- Various fixes for -dtimings
- display the output of -dtimings as a hierarchy

Other OCaml News

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

Back-end Software Engineer at Maxwell Health (Full-time)

News on the Eliom language


NaBoMaMo 2016 writeup

Jackline, a secure terminal-based XMPP client

OASIS-DB sub-project is deprecated.

gesticulations 001

Sixteenth OCaml compiler hacking evening at Pembroke

OCaml Developer at Arena (Full-time)

Version 0.8 of the E-ACSL 0.8 plugin is available for download.

How to Build an Exchange

A brief trip through Spacetime

Lwt 2.7.0

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