Previous week Up Next week

Hello

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

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-06/msg00234.html

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: https://github.com/ocaml/oloop.
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 a.ml 
#use "topfind";;
#thread;;
#camlp4o;;
#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 a.ml
(* 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

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-07/msg00006.html

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:

http://www.fr.mitsubishielectric-rce.eu/images/fck_upload/1506_Annonce_Formal%20methods_PhD_201509_EN(1).pdf

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

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-07/msg00008.html

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
opam:

https://ocaml.janestreet.com/ocaml-core/112.35/files/

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

https://ocaml.janestreet.com/ocaml-core/CHANGES.md
      

looking for "real world" sqlite3 examples

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-07/msg00010.html

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:

  https://github.com/mfp/ocaml-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
macaque:

  https://github.com/ocsigen/macaque

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:
> 
>   https://github.com/mfp/ocaml-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

  https://github.com/mfp/ocaml-sqlexpr#syntax-extension

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

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2015-07/msg00019.html

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
  efficiently.
- Designing online versions of existing combinatorial algorithms.

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

[1]: http://www.umut-acar.org/self-adjusting-computation
[2]: https://github.com/janestreet/incremental/blob/master/src/incremental_intf.ml
[3]: https://github.com/janestreet/incremental/
      

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 http://planet.ocaml.org/.

Unikernels at PolyConf!:
  http://amirchaudhry.com/unikernels-polyconf-2015

POSIX message queues:
  https://forge.ocamlcore.org/projects/mqueue/

Full Time: Software Developer (Functional Programming) at Jane Street in New York, NY; London, UK; Hong Kong:
  http://jobs.github.com/positions/0a9333c4-71da-11e0-9ac7-692793c00b45
      

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