Previous week Up Next week


Here is the latest Caml Weekly News, for the week of June 15 to 22, 2010.

  1. OCaml 3.12.0+beta1
  2. Seeking (Meta)Ocaml / compiler writing help
  3. question about the jvm backend
  4. Other Caml News

OCaml 3.12.0+beta1


Damien Doligez announced:
We have the pleasure of celebrating Bloomsday by announcing the release of
OCaml version 3.12.0+beta1.

This is a beta release, available as source only and intended for power
users to test new features and report bugs (if any).  This release brings
a lot of new features, see the list included below.

It is available here:,
along with the updated reference manual.

Happy hacking,

-- Damien Doligez for the OCaml team.


(Changes that can break existing programs are marked with a "*"  )

Language features:
- Shorthand notation for records: in expressions and patterns,
   { lbl } stands for { lbl = lbl } and { M.lbl } for { M.lbl = lbl }
- Record patterns of the form { lbl = pat; _ } to mark that not all
 labels are listed, purposefully.  (See new warning below.)
- Explicit naming of a generic type; in an expression
 "fun ... (type t) ... -> e", the type t is considered abstract in its
 scope (the arguments that follow it and the body of the function),
 and then replaced by a fresh type variable. In particular, the type
 t can be used in contexts where a type variable is not allowed
 (e.g. for defining an exception in a local module).
- Explicit polymorphic types and polymorphic recursion. In let
 definitions, one can write an explicit polymorphic type just
 immediately the function name; the polymorphism will be enforced,
 and recursive calls may use the polymorphism.
 The syntax is the same as for polymorphic methods:
   "let [rec] <ident> : 'a1 ... 'an. <typexp> = ..."
- First-class packages modules.
 New kind of type expression, for packaged modules: (module PT).
 New kind of expression, to pack a module as a first-class value:
   (module MODEXPR : PT).
 New kind of module expression, to unpack a first-class value as a module:
   (val EXPR : PT).
 PT is a package type of the form "S" or
 "S with type t1 = ... and ... and type tn = ..." (S refers to a module type).
- Local opening of modules in a subexpression.
 Syntax: "let open M in e", or "M.(e)"
- In class definitions, method and instance variable override can now
 be made explicit, by writing "method!", "val!" or "inherit!" in place of
 "method", "val" and "inherit". It is an error to override an
 undefined member (or to use overriding inheritance when nothing get
 overridden). Additionally, these constructs disactivate respectively
 warnings 7 (method override, code 'M') and 13 (instance variable
 override, code 'V'). Note that, by default, warning 7 is inactive
 and warning 13 is active.
- "Destructive" substitution in signatures.
 By writing "<signature> with type t := <typeconstr>" and
 "<signature> with module M := <module-path>" one replaces "t" and "M"
 inside the signature, removing their respective fields. Among other
 uses, this allows to merge two signatures containing identically
 named fields.
* While fixing PR#4824, also corrected a gaping hole in the type checker,
 which allowed instantiating separately object parameters and instance
 variables in an interface. This hole was here since the beginning of
 ocaml, and as a result many programs using object inheritance in a non
 trivial way will need to be corrected. You can look at lablgtk2 for an

Compilers and toplevel:
- Warnings are now numbered and can be switched on and off individually.
 The old system with letters referring to sets of warnings is still
- New warnings:
 + 9 (code 'R') to signal record patterns without "; _" where
   some labels of the record type are not listed in the pattern.
 + 28 when giving a wildcard argument to a constant constructor in
   a pattern-matching.
 + 29 when an end-of-line appears unescaped in a string constant.
 + 30 when the same constructor or record field is defined twice in
   mutually-recursive type definitions.
* The semantics of warning 7 (code 'M', method override) have changed
 (it now detects all overrides, not just repeated definitions inside
 the same class body), and it is now inactive by default.
- Better error report in case of unbound qualified identifier: if the module
 is unbound this error is reported in the first place.
- Added option '-strict-sequence' to force left hand part of sequence to have
 type unit.
- Added option '-no-app-funct' to turn applicative functors off.
 This option can help working around mysterious type incompatibilities
 caused by the incomplete comparison of applicative paths F(X).t.

Native-code compiler:
- AMD64: shorter and slightly more efficient code generated for 
 float comparisons.

Standard library:
- Format: new function ikfprintf analoguous to ifprintf with a continuation
* PR#4210, #4245: stricter range checking in string->integer conversion
 functions (int_of_string, Int32.of_string, Int64.of_string,
 Nativeint.of_string).  The decimal string corresponding to
 max_int + 1 is no longer accepted.
- Scanf: to prevent confusion when mixing Scanf scanning functions and direct
 low level input, value Scanf.stdin has been added.
* Random: changed the algorithm to produce better randomness.  Now passes the
 DieHard tests.
- Map: implement functions from Set that make sense for Map.

Other libraries:
* Str: letters that constitute a word now include digits 0-9 and
 underscore _.  This changes the interpretation of '\b' (word boundary)
 in regexps, but is more consistent with other regexp libraries. (PR#4874).

- Add support for native dynlink.

New tool:
- ocamlobjinfo: displays various information, esp. dependencies, for
 compiled OCaml files (.cmi, .cmo, .cma, .cmx, .cmxa, .cmxs, and bytecode
 executables).  Extends and makes more official the old objinfo tool
 that was installed by some OCaml packages.

All tools:
- PR#4857: add a -vnum option to display the version number and nothing else

Bug Fixes:
- PR#4012: and Map.mapi do not conform to specification
- PR#4478: better error messages for type definition mismatches
- PR#4683: labltk script uses fixed path on windows
- PR#4742: finalisation function raising an exception blocks other
- PR#4775: compiler crash on crazy types (temporary fix)
- PR#4824: narrowing the type of class parameters with a module specification
- PR#4862: relaxed value restriction and records
- PR#4884: optional arguments do not work when Some is redefined
- PR#4964: parenthesized names for infix functions in annot files
- PR#4970: better error message for instance variables
- PR#4975: spelling mistakes
- PR#4988: contravariance lost with ocamlc -i
- PR#5004: problem in Buffer.add_channel with very large lengths.
- PR#5008: on AMD64/MSVC port, rare float corruption during GC.
- PR#5018: wrong exception raised by Dynlink.loadfile.
- PR#5057: fatal typing error with local module + functor + polymorphic
- Wrong type for Obj.add_offset.
- Small problem with the representation of Int32, Int64, and Nativeint
Stéphane Glondu added:
I've successfully recompiled almost all Debian packages with this new
version. There are still a few packages that don't compile [3], either
because they are broken or have broken dependencies.

A list of bugs related to this new version is available at [1]. The
titles of the bugreports should give an overview of practical sources of
incompatibilities (these are not Debian-specific). Some of them are
already fixed (either in upstream repository, or with a home-made patch).=

I've made a (unofficial) repository binary packages for the amd64
architecture, available at [2]. All sources and build logs are available
as well. It might progressively get populated by binary packages for
armel and mipsel. The binary packages should work with current Debian
unstable, and people using testing or unstable can easily test them.
However, please note that OCaml 3.12.0 will most likely not be updated
(and supported) in the official repositories before the next release of
Debian (Squeeze).


> [...] This release brings
> a lot of new features, see the list included below. [...]

Here are some other worthwhile features:

 - Native-code compiler for ARM EABI -> armel becomes a native
   architecture in Debian. Native Dynlink doesn't work, but otherwise
   all packages were compiling natively during my earlier experiments
   with the SVN version.

 - Some support for Findlib in ocamlbuild.

I don't know their official status, though...

Seeking (Meta)Ocaml / compiler writing help


Simon P asked and David Mentré suggested:
> We want to build a small domain specific language and convert it to
> a C-like language. In the process of this source-to-source translation, we 
> want to try partial evaluation followed by relatively simple optimizations 
> (dead code elimination, common subexpression elimination, constant folding, 
> inlining).

It might be interested for you to look at Min-Caml compiler:

Paper describing the compiler:

MinCaml is a complete ML-like compiler compiling to Sparc in about
2,000 lines of code. As far as I remember, it does common
subexpression elimination, constant folding and inlining.

question about the jvm backend


Martin DeMello asked and Xavier Clerc replied:
> I have an OCaml implementation of an algorithm that I now want to use
> from clojure. As I see it, my options are:
> 1. Port to clojure
> 2. Port to scala (better support for pattern matching will make it
> easier to port, also scala might be faster)
> 3. Recompile the OCaml code against the JVM
> (3) seems like the easiest choice, but from what I could gather from
> the docs, there is not much support for generating a library that can
> be consumed by a main program in another language. Is this going to
> change in 2.0?

Well, there are indeed two ways to call OCaml code from another JVM =
  - by callbacks;
  - by scripting.

Callback from a JVM language work similarly to callback from C to
either ocamlc- or ocamlopt-compiled code. This is described in the
fourth chapter of [1], original callbacks being described by the chapter =
However, beware that the representation of OCaml values is going
to change in the upcoming 2.0 version of OCaml-Java.

Scripting is based on the "javax.script" package introduced by JDK 1.6.
It allows to execute arbitrary OCaml code, and can call OCaml compiled
code. It is slower than callbacks, as the script code has to be compiled
at runtime.

Finally, here are some key points that may help you making up your mind:
  - performance in version 2.0 should stand between ocamlc and ocamlopt;
  - version 2.0 will be based on JDK 1.7;
  - hopefully an alpha version should be released during summer, with =
    goal of having a stable version by the end of the year (current =
target of
    JDK 1.7 release).

Feel free to ask for further explanations if needed.


Xavier Clerc


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

I have a dream...:


Tuning the OCaml memory allocator for large data processing jobs:

Concept for a graphical libguestfs browser:

Objective Caml 3.12.0+beta1 released:

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