Previous week Up Next week


Here is the latest Caml Weekly News, for the week of March 06 to 13, 2007.

  1. beta-test of OCaml 3.10.0
  2. ocamlbuild is VERY nifty
  3. ocamlbuild and C stubs
  4. Interactive technical computing
  5. ocaml-developer mailing-list: subscribe now!
  6. STMlib and Enhtop available

beta-test of OCaml 3.10.0


Xavier Leroy announced:
The long-awaited release 3.10 of Objective Caml is making good 
progress and is now ready for beta-testing.  A source-only 
beta distribution can be downloaded from 

We would be grateful if some of you could compile it, give it a 
good workout on your favorite Caml programs, and report any problems 
you might encounter via the Caml bug tracker. 

The main novelties in 3.10 are: 

- A new tool: ocamlbuild, a compilation manager for OCaml projects. 
- Much work on Camlp4, including a new API. 
- A long-awaited feature: stack backtraces on uncaught exceptions 
  that work for native-code as well as for bytecode. 
- Two new 64-bit ports: to Windows 64/AMD64 and MacOS X/PowerPC 64. 

Other changes are listed below. 

The documentation is not up to date yet, but some preliminary 
documentation on ocamlbuild and the new Camlp4 can be found on 
Nicolas Pouillard's Web page, 


- Xavier Leroy, for the Caml development team 


Objective Caml 3.10.0: 

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

Language features: 
- Added virtual instance variables in classes "val virtual v : t" 
* Changed the behaviour of instance variable overriding; the new 
  definition replaces the old one, rather than creating a new 

New tools: 
- ocamlbuild: compilation manager for OCaml applications and libraries. 
  See draft documentation at 
* Camlp4: heavily revised implementation, new API. 

New ports: 
- MacOS X PowerPC 64 bits. 
- MS Windows 64 bits (x64) using the Microsoft PSDK toolchain. 
- MS Windows 32 bits using the Visual Studio 2005 toolchain. 

- Faster type-checking of functor applications. 
- Referencing an interface compiled with -rectypes from a module 
    not compiled with -rectypes is now an error. 
- Revised the "fragile matching" warning. 

Native-code compiler: 
- Print a stack backtrace on an uncaught exception. 
  (Compile and link with ocamlopt -g; execute with OCAMLRUNPARAM=b.) 
  Supported on Intel/AMD in 32 and 64 bits, PPC in 32 and 64 bits. 
- Stack overflow detection on MS Windows 32 bits (courtesy O. Andrieu). 
- Stack overflow detection on MacOS X PPC and Intel. 
- Intel/AMD 64 bits: generate position-independent code by default. 
- Fixed bug involving -for-pack and missing .cmx files (PR#4124). 
- Fixed bug causing duplication of literals  (PR#4152). 

Run-time system: 
- C/Caml interface functions take "char const *" arguments 
  instead of "char *" when appropriate. 
- Faster string comparisons (fast case if strings are ==). 

Standard library: 
- Refined typing of format strings (type format6). 
- Printf, Format: new function ifprintf that consumes its arguments 
    and prints nothing (useful to print conditionally). 
- Scanf: 
    new function format_from_string to convert a string to a format string; 
    new %r conversion to accomodate user defined scanners. 
- Filename: improved Win32 implementation of Filename.quote. 
- List: List.nth now tail-recursive. 
- Sys: added Sys.is_directory.  Some functions (e.g. Sys.command) that 
    could incorrectly raise Sys_io_blocked now raise Sys_error as intended. 

Other libraries: 
- Bigarray: mmap_file takes an optional argument specifying 
    the start position of the data in the mapped file. 
- Dynlink: now defines only two modules, Dynlink and Dynlinkaux (internal), 
    reducing risks of name conflicts with user modules. 
- Labltk under Win32: now uses Tcl/Tk 8.4 instead of 8.3 by default. 
- VM threads: improved performance of I/O operations (less polling). 
- Unix: new function Unix.isatty. 
- Unix emulation under Win32: 
    fixed incorrect error reporting in several functions (PR#4097); 
    better handling of channels opened on sockets (PR#4098); 
    fixed GC bug in Unix.system (PR#4112). 

Documentation generator (OCamldoc): 
- correctly handle '?' in value names (PR#4215) 
- new option -hide-warnings not to print ocamldoc warnings 

Lexer generator (ocamllex): improved error reporting. 

License: fixed a typo in the "special exception" to the LGPL.

ocamlbuild is VERY nifty


Joel Reymont announced:
I asked around before settling on a build system since I'm new to   
OCaml. I looked at OMake, OCamlMakefile and found them complex and   
confusing. Then William Neuman pointed me to ocamlbuild and Nicolas   
Pouillard helped me hook it up to external libraries via a plugin. 
Deep into my first project I confirm that ocamlbuild is VERY nifty. I   
can automatically rebuild when any parts of my project change and   
then run my unit tests. 

All I need to do is: 

ocamlbuild test.byte -- 

*** my project *** 

      189 easy.mli 
      282 easy_lexer.mll 
      420 easy_parser.mly 
     1355 total 

*** *** 

open OUnit 

let suite = "Morpher" >::: 

let _ = 
   run_test_tt_main suite 

*** *** 

open Ocamlbuild_plugin;; 
open Command;; 

let packages = "ounit" (* "pkg1,pkg2,..." *);; 

let ocamlfind cmd = 
S[A"ocamlfind"; A cmd; A"-package"; A packages];; 

flag ["ocaml"; "link"] (A"-linkpkg");; 

dispatch begin function 
| After_options -> 
      Options.ocamlc := ocamlfind "ocamlc"; 
      Options.ocamlopt := ocamlfind "ocamlopt"; 
| _ -> () 

ocamlbuild and C stubs


Shivkumar Chandrasekaran asked and William D. Neumann answered:
> Is there any (easy) way to use ocamlbuild to handle the automatic 
> (re)-compilation of the C stub files to external libraries? Thanks, 

Well, I don't know if it's the best way (I wait for Nicolas to chime in), 
but while playing around with it I tried to get cryptokit to build with 
ocamlbuild.  What I ended up with that worked was a that 
looks like: 
open Ocamlbuild_plugin 
open Command 
open Arch 

let static = false 

let zlib = "-DHAVE_ZLIB" 
let zlib_lib="-lz" 
let zlib_libdir="/usr/lib" 
(* let zlib_libdir=/usr/lib64  (* for x86-64 Linux *) *) 
let zlib_include="/usr/include" 

let libname = "cryptokit" 

let cc_map lst = List.fold_right (fun v b -> A"-ccopt"::(A v)::b) lst [] 
let l_ x = "-L"^x 

let _a = "%.a" 

let c_files = 
   [ "rijndael-alg-fst";  "stubs-aes" 
   ; "d3des"; "stubs-des" 
   ; "arcfour"; "stubs-arcfour" 
   ; "sha1"; "stubs-sha1" 
   ; "sha2"; "stubs-sha2" 
   ; "sha256"; "stubs-sha256" 
   ; "ripemd160"; "stubs-ripemd160" 
   ; "pool"; "stubs-pool" 
   ; "stubs-md5" ; "stubs-zlib"; "stubs-misc"; "stubs-rng" 

let c_objs = (fun f -> f-.-"o") c_files 

let _ = dispatch begin function 
| Before_rules -> 

     rule  "create C library rule" 
         begin fun env build -> 
           let a = env _a in 
           let tags = tags_of_pathname a++"library"++"object"++"archive" in 
           Cmd(S([ !Options.ocamlmklib; A"-o"; A libname ] 
                 @ ( (fun o -> A o) c_objs) @ 
                 [  A(l_ zlib_libdir); A zlib_lib; T tags ] 
     flag  [ "c"; "compile"; ] (S(A"-I"::P".."::(cc_map [("-I"^zlib_include); zlib]))); 
     flag  [ "library"; "ocaml" ] (S[A"-ccopt"; A(l_ zlib_libdir); A"-cclib"; A zlib_lib]); 
     flag  [ "ocaml"; "program" ] (S[A"-ccopt"; A"-L."]); 
     if static then flag  [ "byte"; "link" ] (A"-custom"); 
     flag  [ "byte"; "library"; "link" ]  (S[A"-dllib"; A"-lcryptokit"; A"-cclib"; A"-lcryptokit"]); 
     flag  [ "native"; "library"; "link" ]  (S[A"-cclib"; A"-lcryptokit"]); 
| _ -> () 

The main thing here being the rule to build the C library.  I then use an 
itarget file to build the library.  This contains 


Now, to build the library, I just issue the command 
ocamlbuild libcryptokit.otarget 

And then to build, for example, the test program I use something like 
ocamlbuild test.native -libs nums,unix,cryptokit 

I'm sure there's a bunch of cruft in there that could be better handled, 
but it seems to work well for now.

Interactive technical computing


Deep in this thread, Vu Ngoc San said, Jon Harrop asked, and Vu Ngoc San replied:
> > You probably know it already, but it is very easy to spawn opengl 
> > graphics directly from the toplevel using sdl. Then if you use the 
> > toplevel inside emacs, you get something very similar to the screenshots 
> > you had. 
> > And since you are into screenshots, here is one :-) 
> > 

> This is just the kind of thing that I'd like to hear about! 
> How exactly do you do that? Can you post a complete working example? 
> Looks great... :-)

Thanks :-) 
The idea is that sdl (contrary to glut or lablgtk2), does not have a 
"main loop": so you can write your own. This allows you to open an 
opengl window from the toplevel, and when you quit your mainloop, you 
get back nicely to the toplevel. You can even let the window open when 
you are back to toplevel, but then the graphics are not updated anymore. 
Nice enough: you can later update the sdl window (no need to close it 
and open another one !). 
If you really need interaction in the window and in the toplevel at the 
same time, you can launch the sdl mainloop in a separate thread. It 
really works. But I wouldn't try to open two sdl windows at the same 
time (??). 

I don't have the courage -- and time -- to give you a "working example" 
(see below) but the initialisation is like this: 

  Sdl.init [ `VIDEO ]; 
  Sdlvideo.set_video_mode !window_width !window_height [ `DOUBLEBUF ; 
  Sdlwm.set_caption "Oplot - SDL Window" ""; 

Then you can issue any openGL command you wish. Even from the toplevel ! 

You can also use Sdlttf to handle any ttf font. 


Now, since you sort of asked for it, here it is: 

I have written a small graphics library that does all of this. But this 
is my first ocaml program, first use of openGL etc.. so I'm not 
particularly proud of it. It is quite messy, and in a state of perpetual 
development. You can find a (not so recent) version at 

This lib is actually useful (to me) because you can insert LaTeX 
formulas and export directly to xfig (or postscript). It produces 
postscript of better quality than maple :-) 

There is a (very recent) GUI for this at 

which uses lablgtk2 and launches sdl in a separate thread... (yep. my 
first use of GTK and of threads.. don't be too harsh if you read my 
code... -:) ). However, and even though I'm not a programmer (I do this 
for learning ocaml during my spare time), I'd be happy to have some 
feedback. There is a package with precompiled binaries that works on at 
least three linux machines :-)

ocaml-developer mailing-list: subscribe now!


Martin Jambon anonunced:
There's a new OCaml mailing-list/forum for OCaml software developers:

This forum is centered on practical issues that arise during OCaml
software development.

Appropriate topics for this forum include:

* Which library should I use for doing job X?
* Should I write my own?
* Has anyone had the same problem before?
* How to communicate with other software components written in language Y?
* Project architecture and build tools
* Cross-platform issues
* Web development
* Intensive and distributed computing
* Packaging and distribution
* File formats and implementation of domain-specific languages

Of course all the topics above must be addressed in the context of OCaml

Topics which are excluded from this forum are:

* Learning the OCaml language
* Discussing language extensions without trying to implement and use them
  effectively and and wonderful
places for such things...
Note from the editor:
I will be monitoring this list as well, to publish some messages here.

STMlib and Enhtop available


Zheng Li announced:
I recently announced the availability of these two small piece of code at 
the beginners list [1][2]. Then some people kindly encouraged me to post 
it here also. Here are they: 


This is a user-space implementation of STM (Software Transactional Memory) 
library for OCaml. It's mainly inspired by the STM library of Haskell, with 
some exceptions due to the different nature of languages and different 
strategies of implementation. 

- This library is a user level implementation, whereas the Haskell version is 
based on primitives built into the runtime. 

- This library is purely an add-on to the already existed concurrent library 
of standard OCaml: threads, processes (TODO) and network programs 
(TODO). I.e. you can still program your concurrent applications with all 
facilities already exist in OCaml (e.g. Thread, Event, Unix etc.), but with the 
functions from this library you may transactionally read/write shared data 
instead of using locks or messages (and you may mix them if you really want). 

- There are subtle differences on the signatures and semantics of some 
specific functions between this library and the Haskell version. They are 
documented in the library manual. 

Currently only the threads (also vmthread) back-end is provided as a proof of 
concept. Other back-ends (process and network program), which share the exact 
interface, will come out in future version. The object is being able to write 
one .ml source program, compile once, but link with different back-ends to get 
executables of various execution model for different environments. 

Source code and documents are available at 


This is an experimental patch (we also provide pre-built testing executable and 
Debian package) for an enhanced OCaml toplevel with following features: 

For any kind of bindings (i.e. value, type, module, class etc.): 

  * Identifiers been rebound are shown differently by default, to distinguish 
    with currently effective ones 
  * A new directive to query (by kinds or names or their composition) and show 
    both current and history bindings 
  * A new directive to show the current binding of any identifier without 
    evaluating or rebinding it 
  * A type-check-only testing mode to experiment your definitions without 
    polluting the world, and the directive to enter/leave it 

Documents (running examples and installation instructions) and deliverables are 
available at 

PS. some wrong dependency (on libc6-dev 2.5) in the previously provided Debian 
packages is now fixed. 


Zheng Li then added:
This is a quick bug-fix and features update to Enhtop since the first
release. Main enhancements include:

  * fixed a serious bug of visiting values from opened modules (Thanks Roberto)
  * new directive #env to set toplevel environment configuration. For now,
    which kinds of declarations get pretty printed is configurable, and we
    make a default configuration different from, and hopefully more rational
    than, the original toplevel setting. 
  * new directive #modu to list all the modules at hand and indicate whether
    they are already loaded or not. 
  * #directory now support the removal of path by prefixing "-"
  * #tell can now distinguish which module the current binding is from, in the
    case that more than one modules have the same identifier and all being
  * #tell now allow independent access to a single entry of an external
    module. It prints both the value and the type of the visited entry if 
    the module is already loaded, otherwise only the type is printed.
  * *most* of the directives (both original and newly added ones) now get
    "defaults", i.e., when executed without any arguments, they fall back to
    some predefined default functions, which usually provide relevant
    helping information. e.g. #directory will print out current path setting,
    #load will print out the name of all .cmo and .cma currently available etc.
  * the feedback of some directives is improved.

Check changelog and README from its website for more details and examples. 

One thing you should note that, we do not touch source files other than those
inside the "toplevel" directory. I.e. there is no modification to your
compilers (ocamlc/ocamlopt etc.) and libraries, the compilers themselves and
the executables produced by them should remain identical to the originals. So
you're safe and free to switch to it or switch back. We'd like to get more
feedback from more people to improve it.

Using folding to read the cwn in vim 6+

Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater).

:set foldmethod=expr
:set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1

If you know of a better way, please let me know.

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