Previous week Up Next week


Here is the latest OCaml Weekly News, for the week of June 30 to July 07, 2015.

  1. oloop 0.1.0
  2. PhD position announcement: Timed contracts for Correct-by-Construction system design
  3. Core Suite 112.35.00
  4. looking for "real world" sqlite3 examples
  5. Incremental 112.35.00
  6. Other OCaml News

oloop 0.1.0


Ashish Agarwal announced:
We are pleased to announce the first release of Oloop, which helps you
auto-evaluate OCaml code for inclusion in educational materials such as books
and blogs. An example of the command line tool is below. It evaluates an input
script, silences the output of directives, and prints other output in a manner
similar to the normal OCaml toplevel. Most compiler options such as -
short-paths are supported as well as utop style determination of Lwt and Async
values. This is an early release and we hope additional printers, e.g. to html
and latex, will be added by the community.

The library provides additional power. You create a handle to a toplevel, to
which you can then feed OCaml phrases to evaluate. The types returned are very
precise, so you can define printers exactly to your needs. For example, you
can optionally distinguish between stdout and stderr or merge them, and the
compiler's out phrase is kept distinct from stdout. In educational material,
you often want to show incorrect code. Oloop captures errors, such as syntax
errors, type errors, and exceptions, and returns them as values you can work
with. Scripts can be split into parts by including OCaml comments in the form
(* part N *), so you can include parts piecemeal in your overall text.

Install: Should be in opam soon. Run `opam update`, then `opam install oloop`.
Source code:
API reference: see mli files in the source code, starting with oloop.mli
Command line reference: run `oloop -help`

Please join the project. See the Issues list for small tasks. Bigger tasks
would be to provide a whitespace preserving parser and a syntax highlighter.

$ cat 
#use "topfind";;
#require "core";;
#require "core.syntax";;
open Core_kernel.Std;;
let x = List.reduce_exn ~f:(+) [1;2;3;4;5];;
let () = printf "x = %d\n" x;;

$ oloop -silent-directives
(* part 0 *)
# #use "topfind";;
# #thread;;
# #camlp4o;;
# #require "core";;
# #require "core.syntax";;
# open Core_kernel.Std;;
# let x = List.reduce_exn ~f:(+) [1;2;3;4;5];;
val x : int = 15
# let () = printf "x = %d\n" x;;
x = 15

PhD position announcement: Timed contracts for Correct-by-Construction system design


David MENTRE announced:
INRIA Rennes and Mitsubishi Electric R&D Centre Europe are opening a PhD
position titled "Timed contracts for Correct-by-Construction system design".

Position details are available here:

This PhD position is not strictly related to OCaml but most of the time the
tool developed at MERCE around formal methods are made in OCaml. :-)

Do not hesitate to ask questions if needed. Feel free to forward this position
to relevant forums.

Core Suite 112.35.00


Ben Millwood announced:
I am pleased to announce the release of Core 112.35.00!

The following packages were upgraded:

- async
- async_extended
- async_extra
- async_kernel
- async_parallel
- async_ssl
- async_unix
- bignum
- bin_prot
- core
- core_bench
- core_extended
- core_kernel
- jenga
- ocaml_plugin
- pa_ounit
- re2

and two new packages included for the first time:

- async_rpc_kernel, the platform-independent parts of the Async Rpc library,
- pa_structural_sexp, providing quotation expanders to simplify building
s-expressions from ocaml values.

Files for this release are available on our website and all packages are in

The changelog is large enough that I won't reproduce it here, see:

looking for "real world" sqlite3 examples


Martin DeMello asked and Erkki Seppala replied:
> I need to integrate an sqlite database in an app of mine, and I'm
> trying to find existing code I can look at to get some idea of how to
> go about it. I tried mirage/orm, but ran into some problems (I
> reported the issue, and the author said the code hadn't been
> maintained for a while), so I'm falling back on the idea of using
> sqlite3 directly.
> Things I am interested in:
> 1. database schema, versioning and migrations - will i need to do
> those independently via sql/shell scripts, or is there some good way
> to integrate them into my ocaml code?
> 2. type conversions - in the absence of an orm, do i have to write my
> own by hand per resultset. or is there some intermediate-level library
> that i haven't found that would automate some of it?
> 3. is there a maintained library for generating sql queries in a typed manner?

You should look into SqlExpr:

I used it recently for a very small project, and it seemed to work
great, even if it doesn't ensure compile-time type safety like PGOCaml.

What I would really like would be a database interface that would work
with both PostgreSQL and SQLite. Apparently ODBC bindings for OCaml
exists, so it would work, but I haven't really tried it out yet.. In
particular I would miss SqlExpr :).

> But mostly, I want to look at someone else's code and get an idea of
> how this is done in ocaml; pretty much all my database code to date
> has been written in dynamically typed languages and relied on code
> generation.

I just write the queries in this small case. It doesn't really allow
dynamically composing new queries out from old ones. For that there is

I haven't tried it for a long time, apparently it has matured quite
a bit.
Mauricio Fernández then replied:
> You should look into SqlExpr:
> I used it recently for a very small project, and it seemed to work
> great, even if it doesn't ensure compile-time type safety like PGOCaml.

There's a mechanism to unit test the queries automatically (ensuring that
they're coherent with the DB's schema) which can be integrated in the regular
build process, able to catch many (most) problems (syntax errors,
missing/misnamed/ambiguous columns/tables, etc.), see

It works by collecting all the statements that constitute the schema (marked
as "sqlinit") along with the remaining regular queries ("sql" / "sqlc"), and
then generating functions that initialize an empty DB and prepare all the
statements against it (similarly to what PGOCaml does at compile-time).

This can also serve as "early run-time checking", arguably stronger than
PGOCaml in a way (because you can verify that the queries are valid against
the DB's current schema, not against the one you had when compiling).

If you're using OUnit and all your DB-related code lies in module MyDB,
you can do something like this to unit test the SQL queries:

    open OUnit

    let test_sql f () =
      let b   = Buffer.create 13 in
      let fmt = Format.formatter_of_buffer b in
      let contents b = Format.fprintf fmt "@?"; Buffer.contents b in
        if not (f fmt) then
          assert_failure (contents b)

    let tests =
      [ "SQL tests" >:: test_sql MyDB.auto_check_db;
       run_test_tt_main ("All" >::: tests)

Incremental 112.35.00


Yaron Minsky announced:
I'm very pleased to announce the release of Incremental 112.35.00.

Incremental is a library for building self-adusting computations,
following the work of Acar et. al. [1]. Self adjusting computations
are designed so that they can be updated efficiently in response to
their inputs.  Incremental can be useful in a number of different
kinds of applications, including:

- Building large calculations (of the kind you might build into a
  spreadsheet) that can react efficiently to changing data.
- Constructing views in GUI applications that can incorporate new data
- Designing online versions of existing combinatorial algorithms.

You can find detailed documentation of the library and how to use it
in [2].  The full source is on github [3], and it
should show up in opam shortly as well.


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

Unikernels at PolyConf!:

POSIX message queues:

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