Previous week Up Next week


Here is the latest OCaml Weekly News, for the week of May 10 to 17, 2016.

  1. Simple library to manipulate automata?
  2. IDE like PyCharm - Results
  3. Ocaml and Windows' notion of Unicode file names
  4. Batteries 2.5.0, compatible with OCaml 4.03
  5. BuckleScript (A js backend for ocaml)
  6. Next OUPS meetup, 7th of June 2016
  7. Ocaml Github Pull Requests
  8. Other OCaml News

Simple library to manipulate automata?


David Mentré asked:
I would like to manipulate some basic automata in OCaml: creation, execution,
minimization, display, etc.

Before re-inventing the wheel, do you know a library doing that?

From my own searches, I only found "automatx"
( which seems to suit my needs but (1) has
a French API and (2) has no license information.
Török Edwin replied:
There is safa/symkat on opam [1]. It has various automata minimization
algorithms, NFA -> DFA, print to .dot format.
Although it is meant for equivalence checking, so it may not be 'simple' to use
for actually executing the automata, and beware that the syntax for its parser
is not the usual regex [2].
(of course you can construct the automata with the API instead of parsing from a
string to avoid this).

See below for some code that I wrote a while ago to visualize a DFA using


 * $ ocamlfind ocamlopt -package safa,symkat -o printnfa -linkpkg -rectypes
 * $ ./printnfa >
 * NFA states: 7
 * DFA states: 5
 * $ dot -Tsvg -o test.svg
 * $ firefox ./test.svg
let trace_dfa a states =
  let trace = Automata.SDFA.trace Format.pp_print_char Format.pp_print_char
      (Bdd.print_formula 0) in
  Trace.clear ();
  trace a states;
  print_endline (Trace.render false "\"")

let print_nfa x =
  let a,f = Automata.SNFA.reindex (Antimirov.nfa()) in
  let states = f (Antimirov.split x) in
  let number_of_states, _ = Automata.SNFA.size a states in
  Printf.eprintf "NFA states: %d\n%!" number_of_states;
  let a = Determinisation.optimised a in
  let number_of_states, _ = Automata.SDFA.size a [states] in
  trace_dfa a states; 
  Printf.eprintf "DFA states: %d\n%!" number_of_states

let print_dfa x =
  let a = Brzozowski.dfa () in
  let number_of_states, _ = Automata.SDFA.size a [x] in
  Printf.eprintf "DFA states: %d\n" number_of_states

let () =
  let e = Parse.expr "x*x*x*x*x*(x+y)z" in
  let x,_,_ = Hypotheses.eliminate [] e e in
  print_nfa x;
Spiros Eliopoulos also replied:
Two libraries come to mind. I and others on the Frenetic[0] team have used both
at various points in time to implemented automata-related algorithms. The first
is a project called DPRLE. You can find its home page and my GitHub clone of the
SVN repository below:

The second is a library that I wrote called TDK. It implements a generalization
of BDDs, allowing for variables to have a lattice structure and terminal nodes
to have something like a semi-ring structure. You can find the GitHub repository

Last I checked, TDK is on OPAM, while DPRLE is not. Hope this helps!

-Spiros E.


IDE like PyCharm - Results


Continuing the thread from last week, Benjamin Greenman said:
You might like Sublime Text with
Leonardo Laguna Ruiz also replied:
If you are willing to try one more alternative, I use Sublime Text 3 plus the
plugin of merlin.

I use this project "template" in every project I start.

Merlin through sublime text works quite well. The only problem I have had is
with projects of tens of thousands lines of code, the autocomplete gets slow. In
such cases I turn it off.

Sublime text is an excellent editor. Looks a lot like Atom but Sublime text is
much faster and responsive.

Ocaml and Windows' notion of Unicode file names


Andreas Rossberg asked:
Does anybody have advice for dealing with unicode file names under Windows? In
particular, my problem is that the following invariant

  let files = Array.to_list (Sys.readdir “.”) in
  assert (List.for_all Sys.file_exists files)

does not hold under Windows, because some of the file names returned by readdir
are not valid.

The Unix emulation module has the same issue.

This is only partially Ocaml’s fault — I see that it implements Sys.readdir and
Unix.readdir using Windows’ ASCII _findfirst and _findnext functions, which
apparently just replace large code points with ‘?’. And I’m not sure how
realistic it would be for Ocaml to switch to Windows' wchar APIs and, say,
UTF8-encode/decode file names on its side.

But anyway, I’m wondering who else has run into this, and has an idea how to
cope. Because I came up blank.
Adrien Nader replied:
There was a thread about this back in february:
  "Looking for a windows ocaml UTF-16 encoded filename aware library".
Matthieu Dubuget then added:
the thread pointed by Adrien lists different solutions. One of them is to write
a lightweight unicode-aware library. A cleaner solution is also currently
proposed as a pull request against OCaml standard library

I tried the "small library" solution, which worked pretty well, but in my
use-case, it appeared to be extremely slow. I did not yet test a mixed solution,
that would switch to unicode versions of the calls, only when the non-unicode
one are failing. Nor did I tried yet the pull request #153.

Note that on windows, there are two different problems to address when dealing
with paths. The more obvious one is their encoding. But you may also experience
problems depending on their length. In this case, the solution is to use
unicode-aware calls, and to specify an extended-length path, using the "\\?\"
prefix. For example, "\\?\D:\very long path". I also have to check if this is

Batteries 2.5.0, compatible with OCaml 4.03


Gabriel Scherer announced:
## Batteries

Batteries Included is a community-maintained standard library
extension, with a focus on stability and compatibility. Bug reports,
pull requests and other contributions are warmly welcome, see the
project page at

The library's API documentation at:

Batteries 2.5.0 is a minor release, coming shortly after 2.4.0
released in December 2015. The main change in 2.5.0 is that it is
compatible with the newly released OCaml 4.03.

Note that, as usual for Batteries release, Batteries 2.5.0 is
compatible with older OCaml releases as well, and provides back-ported
versions of most standard library functions made available in 4.03
only. For example, BatString.uppercase_ascii is usable under all OCaml

If the documentation of a Batteries function says
  @since 2.5.0
then it is available under all supported OCaml versions (3.12.1 and
up). If it says
  @since 2.5.0 and OCaml 4.03.0
then it is only available under OCaml 4.03.0.

Many thanks to the contributors for this release, Cedric Cellier,
Pieter Goetschalckx KC Sivaramakrishnan, Gabriel Scherer, and Thibault

## Detailed Changelog

- BatTuple: add Tuple{N}.make : 'a1 -> ... -> 'an -> 'a1 * ... * 'an
  (Thibault Suzanne)
- BatBig_int: fix sequence operators (--), (---) to avoid polymorphic comparison
  #674, #675, #676
  (Pieter Goetschalckx and Cedric Cellier)
- Extend all Batteries module to cover OCaml 4.03 features
  (Gabriel Scherer, KC Sivaramakrishnan)

## Future plans

OCaml 4.03 introduced a type `('a, 'b) result` contributed by Yaron
Minsky, meant to serve as common denominator between the various
libraries relying on some kind of sum/either type.

    type ('a,'b) result = Ok of 'a | Error of 'b

Batteries has long had its own `result` type, which unfortunately uses
a different name for the second constructor:

    type ('a, 'b) result = Ok  of 'a | Bad of 'b

Unfortunately, this means that the two types are incompatible (see
PR#7102 for a feature request on renaming variant
constructors). Batteries 2.5.0 is compatible with previous Batteries
versions, and keeps using Batteries' result type.

Of course, the right long-term move for Batteries is to drop its own
result type and use the standard result type instead. But this means
a breaking change for our users as well. We plan to make a major
release 3.0 in the following months, that integrates this breaking
changes and some other incompatible interface changes that were
proposed over the 2.x lifetime.

Happy hacking!
Christoph Höger asked, Matej Kosik added, and Gabriel Scherer replied:
>> Unfortunately, I am unable to use some modules:
>> consider the following simple test:
>> % cat
>> let () = Printf.printf "%s\n" Batteries.Sys.os_type
>> % ocamlbuild -pkg batteries foo.native
>> ...
>> File "_none_", line 1:
>> Error: No implementations provided for the following modules:
>>          BatConcreteQueue_402 referenced from
>> [..]/opam/4.02.3/lib/batteries/batteries.cmxa(BatQueue)
>>          BatOpaqueInnerSys referenced from
>> [..]/opam/4.02.3/lib/batteries/batteries.cmxa(BatSys)
>> Command exited with code 2.
>> This is opam 1.2.2, OCaml 4.02.3 and batteries 2.5.0
>> Did I break something or is this an actual bug?

> In my context, after switching to 4.02.3, I noticed the same problem.

There is indeed a packaging problem with 2.5.0 -- I did two quick
bugfix releases in succession, and 2.5.2 should land in opam any time
now. Apologies for the hiccup.

BuckleScript (A js backend for ocaml)


Hongbo Zhang announced:
Dear OCaml developers:
We are glad to announce BuckleScript[1], a backend for the OCaml compiler which
emits JavaScript. The project's goal is to bridge the OCaml and JavaScript
ecosystems in a seamless way. As examples of that vision, using BuckleScript,
OCaml users can use Chrome Dev Tools to debug OCaml code, while Javascript users
can use OCaml libraries as plain npm[2] packages. 
The project is inspired by js_of_ocaml[3], and the differences are documented
here[4]. While it is not production-ready yet, we've reached a point in the
development where we feel comfortable encouraging you to try it and 
share your feedback with us. 


Next OUPS meetup, 7th of June 2016


Louis Roché announced:
The next OUPS meetup will take place on the 7th of June 7pm. The location is not
defined yet.
We will have a few talks, followed by pizzas.

The talks will be the following:

- Danny Willems: Bindings OCaml à Cordova grâce à js_of_ocaml et gen_js_api 
- Frédéric Bour: sturgeon — A toolkit for communicating with Emacs from OCaml

Note that we are always in demand of talk *proposals* for future

To register, or for more information, go here:
*Registration is required!*

Slides from previous sessions are available online:

Ocaml Github Pull Requests

Gabriel Scherer 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.

Make OCaml native debugging awesome

Other OCaml News

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

OCaml 4.03.0 released

Tail call optimisation in (g)awk

Batteries 2.5.0 released, compatible with OCaml 4.03

Configuration DSL step-by-step

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