Previous week Up Next week


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

  1. Ocaml-related jobs, Boston area
  2. 2D graphing and charting
  3. A sound semantics for OCaml light
  4. Scanf and segfaults
  5. Wink releases caching library
  6. debugging memory leaks
  7. Findlib-1.2 released

Ocaml-related jobs, Boston area


Matteo Frigo announced:
I apologize for spamming this list to which I do not usually 
participate, but I would like to make you aware that Cilk Arts is 
hiring and that a good chunk of our development is done in Objective 
Caml.  We are based in Lexington, MA, USA. 

Cilk Arts is a venture-backed startup originally founded by 
prof. Charles Leiserson and myself to bring to the marketplace the 
large body of research done at MIT on Cilk in the past 15 years.  Some 
long-timers may remember that our Cilk team won the first 
International Contest on Functional Programming in 1998.  We are big 
fans of ocaml (some of you may be familiar with my own work on FFTW). 

Our website gives details about the company, products, 
and job positions.  I would appreciate if you could forward this 
announcement to anyone whom you think could be interested.

2D graphing and charting


Jon Harrop asked:
I've been using Mathematica to render the graphs on our site, like the ray 
tracer language comparison: 

What free OCaml software might I use to do the same thing?
Till Varoquaux suggested:
There is an interface to gnuplot. I've never tried it:
Hezekiah M. Carty also answered:
There is at least one partial plplot ( 
binding already in existence 
(, and I'm working 
on another one using camlidl rather than Swig. 

I haven't put my code out yet because I'd like to finish up some of 
the 3D plotting function wrappers first, but if you're interested in 
having something sooner I could put out what I have currently.  There 
is enough there to do 2D plots, and the naming follows the C-library 
quite closely. 

The already-mentioned gnuplot binding seems to work reasonably as 
well, though I've only made very basic 2D plots with it. 

PsiLab ( is older, and based on OCaml 
3.01 or 3.02 I think.  But I've been able to get it to build on recent 
Linux distributions.  It has a fairly high-level binding to the plplot 
libraries which is quite easy to use.  I have dreams of some day 
updating it to work with recent OCaml releases.  It might also be a 
decent start for a Mathematica-like toplevel with inline plots and so 
on if the toplevel customizations could be tied in to labltk or 
lablgtk.  I don't know how possible this is though.
Peng Zang also answered and Paul Pelzl added:
> I've used mlgrace in the past: 
> Although I've never tried labelled points before...  I also have a convenience 
> interface to it that I've written so I can do stuff like: 
>   Plot.plotfun (( ** )2.) 0. 10. 0.1 "ro-";; 
> and have it plot x^2 from 0 to 10 in 0.1 steps with a red line and dotted data 
> points.  It's not packaged up nice at all, but I'm happy to share it if 
> you're interested. 

mlGrace does not currently expose an API to create point labels, but the 
xmgrace GUI can do this (under Plot->Set Appearance->Ann. values).  So 
something similar to Jon's example plot could be generated using 
grace_view#plot_many, with a small amount of touch-up work from the GUI.

A sound semantics for OCaml light


Scott Owens announced:
We are pleased to announce the public release of OCaml light, a   
formal semantics for a substantial, practical subset of the Objective   
Caml language. It is written in Ott, generating proof assistant   
definitions for HOL-4 and (in draft form) Coq and Isabelle/HOL. It   
comprises a small-step operational semantics and a syntactic, non- 
algorithmic type system. A type soundness theorem has been proved and   
mechanized using the HOL-4 proof assistant. To ensure that the   
operational semantics accurately models Objective Caml, an executable   
version of the semantics has been created (and proved equivalent in   
HOL to the original, relational version) and tested on a number of   
small test cases. 

For more information please visit

Scanf and segfaults


Deep into this controversial thread, Oliver Bandel said and Pierre Weis replied:
> Segfaults in OCaml are seldom, but nevertheless 
> those seldom seen segfaults should be fixed. 

> The original poster stated out that the bug he 
> posted was four months on status "new". 

> This was a littlebid astonishing, and possibly 
> the reason why this thread was started. 

I think this is my fault: I implemented Scanf in the first place. 

May be some of you missed the point in the segfault example involving Scanf 
that was given on this list: the example involves using positional parameters 
in the string argument passed to sscanf and using meta format specifications 
in the format string argument. 

Positional parameters: 

Positional parameters are parameters number specifications that allows format 
strings to refer to another parameter than the next in the presentation 
order. This is supposed to be useful for internationalization where you can 
change the printing order of the parameters to reflect the translation. 

This new feature has only been introduced in the documentation for Printf 
just after the successful correction of the long standing strange behaviour 
of printf with respect to partial evaluation. Positional parameters have 
never been mentioned in the Scanf documentation and Scanf is not supposed 
to supported them. 

To say the least, this feature is still experimental and not yet completely 
implemented in the current sources of the compiler. In fact, the typechecker 
abruptely rejects format strings with positional parameters, as exemplify 

# Printf.printf "%2$i %1$s" "toto" 1;; 
Bad conversion %$, at char number 0 in format string ``%2$i %1$s'' 

As mentioned above, Scanf is not supposed to handle positional parameters, 
and indeed rejects them at runtime in the format string (this could seem 
overkill, given that the type-checker rejects positional parameters in the 
first place, but well, 2 checks are better than one!). 

Meta format specifications: 

However, Scanf is still capable to read a format string lexem given in the 
input, provided the format used to read this lexem involves a meta format 
that properly describes the format string lexem to be read. For instance: 
Scanf.sscanf s "%{ %i %f %}" is supposed to read in the input (the string s) 
a format string that specify to read first an integer, then a floating point 

A more practical working example could be: 

# let fmt = 
    Scanf.sscanf "\"Reference: %i      Price : %f\"" "%{%i%f%}" 
      (fun fmt -> fmt);; 
val fmt : (int -> float -> '_a, '_b, '_c, '_d, '_d, '_a) format6 = <abstr> 
# string_of_format fmt;; 
- : string = "Reference: %i      Price : %f" 

This features allows a procedure to read the format string it has to use to 
read a file: the procedure just reads the format as the first line of the 

The example seg-fault analysis: 

So, the seg-faulting example given is quite involved, since it uses scanf's 
capability to read a format string in the input, in order to create a format 
string with positional specification. This was clearly unexpected, given the 
``axiom'' that says "the type checker will prevent that in the first place 
since it rejects any positional parameter!". In this case, the typechecker 
cannot reject the format string given in the program, since it has no 
positional specification; and it cannot reject the format read, since this 
format is unknown at compile time! 

This simply means that there is a bug in the type compatibility runtime test 
for format strings that fails to properly reject positional parameters. This 
is not difficult to correct, if not at all satifactory. 

The corrections or problem suppression: 

I once thought that introducing positional parameters in Scanf, Printf, and 
Format, would be a piece of cake in comparison to correcting the hard bug of 
printf's treatment of partial evaluation (this ``misfeature'' stood there for 
more than 10 years, before a correction can be figured out). Unfortunately, I 
was wrong, positional parameters are not at all easy, even when the printf 
behaviour is corrected: admittedly, the runtime implementation for positional 
parameters was not too hard for Printf and it has been done quickly; on the 
other hand, the type checking of format strings with positional parameters 
proved to be untrivial: you need a deep breath to dig into the old code, you 
need once more understand it in depth, and basically you must rewrite it with 
a new logic that supports positional parameters. This has not yet been done, 

In conclusion, I have to correct the runtime compatibility check for formats 
to suppress the problem, and remove any mention of positional parameters from 
the documentation, until I achieve the new type checking stuff for format 

Or just give up on this complex feature that has already upset too many people. 

I agree with any one who cares that I was wrong to introduce a not yet 
properly baked feature in Caml. The natural over optimistic tendancy of my 
researcher's enthousiasm caught me there ... 


> I for myself have only stated that I hope the bugs will be fixed. 

I hope them to be fixed as well. Sometimes it's difficult. Sometimes we lack 
the time and concentration to find the solution. Even worse, sometimes we 
never find the solution for years... 

Best regards, 

PS: You can check in the bug tracking system that there are more than one 
message concerning positional parameters in format strings, and that I 
already answered to a lot of them.

Wink releases caching library


Gerd Stolpmann announced:
Wink Technologies, Inc., the makers of the soon-to-be-famous people 
search engine (, have just released another OCaml 
library, this time for caching data: 

"Cache implements a caching service for storing arbitrary strings that 
can be located by string keys. The caching service is reachable over 
TCP. The cache can be distributed over several nodes. The cache can be 
saved to disk in regular intervals. A client module is included. Both 
synchronous and asynchronous access methods are defined." 

Downloadable at There is also a manual: 

There is also a GODI package for it (godi-cache). 

N.B. The library has been in production for more than a year. It's 
rock-stable and fast, and runs 24x7 without any problems.
Joel Reymont asked and Gerd Stolpmann answered:
> Why did you guys roll your own instead of using memcached? 

We considered using memcached. However, there is no client for OCaml, 
and especially no asynchronous client, so we would have had to write 
one. I looked at the protocol, and it turned out to be weird, ad-hoc, 
and not very extensible. It would have been no fun developing such a 

In contrast, for developing our own caching server, it was not necessary 
to write any new networking code: By using the SunRPC library of 
Ocamlnet we got the whole communication stuff for free, and the protocol 
is now well-structured and easily extensible. Furthermore, we could 
tailor the features to our requirements, and have the guarantee that we 
can adapt the server to any changes. 

Actually, we needed only 1 day for developing the library, and another 
day for integrating it. This is what other companies spend for 
evaluating external software they might want to use. So the costs were 
justified, and we now have exactly the software we wanted. 

So the essence is: By using good tools (OCaml, Ocamlnet, etc.) we can 
develop the software ourselves with the same costs as the integration of 
an external component would have taken. Plus, we have perfectly adapted 
software, and are on the safe side for the future. Sounds like a good 
deal, right?

debugging memory leaks


Chris Waterson asked and Pierre Etchemaïté answered:
> I have a fairly substantial OCaml application that leaks memory.   
> What tools or techniques do people use to track down memory leaks?   
> Minimally, is there a way to enumerate the live objects in the heap? 

There's ocaml-memprof, a compiler patch that adds memory profiling 
features to ocaml programs; 

Latest update of the patch itself, as far as I know: 


Findlib-1.2 released


Gerd Stolpmann announced:
findlib-1.2 is available. This version focuses on supporting Camlp4-3.10 
properly, and making it work on Win32. There are also a few other fixes 
and enhancements. 

For Camlp4 there are now special packages that match the available 
extensions on O'Caml 3.10. For example, you can now request -package 
camlp4.listcomprehension to enable the list comprehension extension. 

The Win32 fixups have only been tested with the mingw port of O'Caml. 
Please read the INSTALL instructions carefully. 

For general information about findlib, see 

A full list of changes can be found inside

The new tarball is available under

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}$'?'&lt;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