Previous week Up Next week


Here is the latest Caml Weekly News, for the week of July 03 to 10, 2012.

  1. ocaml top-level line editing script
  2. ReML, a library for combinatorics
  3. google-drive-ocamlfuse 0.1-pre2
  4. Agda-style parser
  5. 4.00.0 is coming
  6. stream parsers with location information?
  7. pretty-printing with camlp4?
  8. ocaml-safepass 1.0
  9. file specific outputting
  10. Other Caml News

ocaml top-level line editing script


Aaron Bohannon announced:
One thing that is missing from the OCaml top level loop is line
editing features. I used to use a wrapper program called "ledit" that
added readline support, but I never seem to have it installed on my
machine when I need it, and moreover, I have started to get used to
the more flexible line editing of zsh.

After some poking around, I found that it's fairly straightforward to
wrap any REPL with a zsh script and get zsh line editing capabilities,
which includes multi-line support (e.g., so you can fix a typo you
made three lines back).

I'm attaching the script I hacked together, in case it is useful to
anyone else. It works great for me, but it was not written to be
generic and robust, so YMMV. You must use ctrl-D to exit cleanly -- I
didn't bother adding support for "#quit". I'm sure someone could make
many improvements to it if they had more patience for zsh scripting
than I do.

(Find the file at the archive link above.)
Markus Weißmann suggested:
rlwrap? [1] Its probably already available through your favorite package manger.


rixed added:
Interesting, although rlwrap gives you history, filename completion,
prompt coloring, syntax completion, brackets matching, use of an
external editor and easy configuration via .inputrc.

For instance I have this in my .zshrc:

alias ocaml='rlwrap --prompt-colour=green --multi-line --remember 
--complete-filenames --command-name=ocaml ocaml -rectypes'

And this in my .inputrc:

$if ocaml
"\C-o": "()\C-b"
"\C-n": ";;\n"

While the default C-^ launches vi (for multi-line edits)

ReML, a library for combinatorics


Jean-Christophe Filliâtre announced:
This is our pleasure to announce the first release of ReML, an OCaml
library for combinatorics.

This library provides the following modules:
- Dlx: Knuth's dancing links
- Zdd: Zero-suppressed binary decision diagrams
- Emc: a common interface to modules Dlx and Zdd to solve the Exact
  Matrix Cover problem
- Tiling: converts a 2D tiling problem into an EMC problem


ReML also contains an interpreter for a language to describe 2D tiling
problems (such as Pentominos) and to solve them or to enumerate their
solutions. The source tarball contains some examples.

Web page:

google-drive-ocamlfuse 0.1-pre2


Alessandro Strada announced:
I'm developing a FUSE filesystem over Google Drive using ocamlfuse.
The project is hosted on OCaml Forge
( and on github
( I've also
uploaded the package on oasis-db

In this pre-release, I've implemented enough FUSE operations to
provide a read-only access to the files stored on Google Drive. Before
implementing the write operations, I would like to have some feedback
from real users to see if someone finds this project useful and to
check if my implementation is working. I've set up a mailing list on
the forge (
where you can post questions, suggestions or report problems. Or, if
you want, you can open issues on github.

Before trying this application, please read the wiki pages containing
info about authorization
and configuration
Goswin von Brederlow suggested:
You can use my fuse bindings for ocaml:;a=summary

Agda-style parser


Andrej Bauer asked and Gabriel Scherer replied:
> If I wanted a parser in Ocaml that can parse things in the style of
> Agda (with the cool underscore thingy), where would I start looking?

My advice would be to mimic Agda's conceptual two-pass process: parse
only the static Context-Free Language structure of your language,
parsing "expressions" (or any syntactic class that admits mixfixes)
into just a list of non-terminals (plus parenthesing, if you assume
your mixfixes are all well-balanced wrt. symmetric delimitors). This
can be done easily with existing OCaml parser or parser generator
technology (menhir). Then, in a later pass, you compute mixfix
definitions/scopes and add this structure to the parsetree, using a
custom algorithm that has been described in the Agda literature (or
non-Agda previous work), eg.

This is a clean way to handle this and, I believe, one of the simplest
to use, understand and debug.
Jérémie Dimino also suggested:
You can have a look at dypgen [1]. Actions can extend the grammar.


4.00.0 is coming


Damien Doligez announced:
We are in the last stages of fixing bugs before 4.00.0 is released.
If your favorite bug report is still open and you want to know
whether we will fix it before 4.00.0, look at its "Target Version"
field. If this is 4.00.0+dev, we are trying hard to fix your bug.
If it is not and you want to insist that we fix your bug before
the release, just drop me a note. I'm not making any promise,
but we will carefully review your bug before taking a decision.

stream parsers with location information?


Nicolas Ojeda Bar asked and Gabriel Scherer replied:
> Is there a clean way to use stream parsers/lexers if I want to have
> location (line number, character position) information attached to
> each token?

Indeed: you need your lexer to produce location information. Instead
of manipulating a (token Stream.t), you will produce (and then parse
at the lexer level) a ((token * location) Stream.t).

This is the way Camlp4 parsers are implemented (recursive descent over
a stream of tokens and positions). See also "Planck", an experiment at
combinator parser libraries by Jun Furuse, using a similar (but
different) architecture.

pretty-printing with camlp4?


Nicolas Ojeda Bar asked and Gabriel Scherer replied:
> Is it possible to use Camlp4 to write pretty printers of arbitrary
> data? The signature Camlp4.Sig.Printer seems to indicate the pretty
> printing facility only works with OCaml ASTs...
> On the other hand, with Camlp5 it is possible to write pretty
> printers for arbitrary ASTs
> (see,
> so I imagine there must be a way to do the same thing with Camlp4...

As far as I know, no such facility exists in Camlp4.

Note however that there is quite a difference between parsers and
printers. Supporting extensible parsing is very difficult, because
parsing is quite a complex process. On the contrary, "printers" as
presented here or as implemented in Camlp4 are more like regular tree
traversals, calling a pretty-printing library that takes care of the
visual formatting aspects. An "extensible printer" can therefore be
summarized as an extensible tree traversal, something that is not too
difficult to achieve with a decent software architecture; for example
Camlp4's MapGenerator framework.

If you don't need the "extensible" parts of Camlp5 printer's support,
because your datatype to print is fixed, you can use the
pretty-printing library directly. Camlp4 uses the Format module of the
standard library, but I personally found it to be a bit painful to
use, and have a preference for the Pprint library of François Pottier:

(There are other pretty-printing libraries for OCaml that I haven't
tried, such as Martin Jambon's easy-format: )

My advice would be to use one of those pretty-printing libraries, to
see if it fits your bill, or if you really need another abstraction
layer such as Camlp5 printers.
(Of course you can also use Camlp5 directly if it solves you problem.)

ocaml-safepass 1.0


Dario Teixeira announced:
The registration of users with login + password is a common feature in 
web sites.  And as you know, this login data is a valuable prize for
attackers.  Therefore I'm happy to announce the availability of version
1.0 of OCaml-safepass, a simple library offering facilities for the safe
storage of user passwords.  By "safe" I mean that passwords are salted
and hashed using the Bcrypt algorithm [1].  Salting prevents rainbow-table
based attacks [2], whereas hashing by a very time-consuming algorithm such
as Bcrypt renders brute-force password cracking impractical.

OCaml-safepass's obvious usage domain are web applications, though it
does not depend on any particular framework.  Internally, OCaml-safepass
binds to the C routines from Openwall's Crypt_blowfish [3].  However,
it would be incorrect to describe OCaml-safepass as an OCaml binding
to Crypt_blowfish, because the API it exposes is higher-level and more
compact than that offered by Crypt_blowfish.  Moreover, OCaml-safepass's
API takes advantage of OCaml's type-system to make usage mistakes nearly

Here is the project website:

The API documentation is also available on online:

Feedback is more than welcome!
Best regards,
Dario Teixeira


file specific outputting


Dash, Santanu asked and Jérémie Dimino replied:
> I work in the area of program analysis. I am currently trying to analyse 
> Ocaml programs and wish to output file-specific information with the aid of 
> the Ocaml compiler.
> For example, if I compile a file called, i want to output a file 
> called based on an analysis of I have already integrated 
> the analysis module with the Ocaml compiler.
> Can someone direct me on the best way to go about this? Is there a variable 
> in the compiler that stores the filename of the file currently being compiled?

There is Location.input_name. It is set by the compiler before parsing
a source file (file "driver/", function "file"). Note that if
there are multiple source files on the command line it will be
modified for each one of them.

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

Existential Crisis:

Half-hearted hash table:

PG'OCaml 1.6 released:

Opa 1.0.4 Released:

Major change soon...:

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