Previous week Up Next week


Here is the latest Caml Weekly News, for the week of 15 to 22 March, 2005.

  1. OCaml mentioned in BraveGNUWorld
  2. Printing values
  3. how to "disable" GC?
  4. OCaml troll on Slashdot
  5. Help on Event module wanted
  6. demexp 0.4.0
  7. Tail Recursion on Map, Append, etc.
  8. a tiny ocaml/ocurl program for frequent flyers (on United Airlines)
  9. Objective Caml 3.08.3
  10. Release of Numerix-0.21
  11. Sandboxing in ocaml

OCaml mentioned in BraveGNUWorld


Oliver Bandel said:
A small tool I wrote (mbox-cleaner) was mentioned in
the current BraveGNUWorld.
OCaml was mentioned there too and it was written,
that "for a scripting language it's fast". ;-)

So maybe OCaml will be more known in the future, if people
would do more marketing on it. ;-)

(But other things written in that article were not all correct :(
 but ... well...... )
(in german only)

(I don't know why since many months there are no english translations of the
BraveGNUWorld ...)...)

Printing values


Christian Stork asked and Richard Jones answered:
> This must be a dumb question, but I couldn't find an answer.
> How can I print values of my own data types in the default way, eg, as
> the debugger or the toplevel does it?  Is there a standard formatter
> that I can use (or generate), or do I have to write a new formatter for
> each data type? 

One solution is to use Std.dump in Extlib[1].  It's not (AFAIAA)
available in any released version of Extlib, so you'd have to use the
CVS version, or use the original standalone version from which it is


Yoann Padioleau also answered:
you can try this:

or this (better):

how to "disable" GC?


Continuing the thread from last week, Ken Rose asked and Damien Doligez answered:
> > So if you allocate some things that go directly into the major heap
> > (for example reasonably large arrays or strings) you need a big major
> > heap as well as a big minor heap:
> >   setenv OCAMLRUNPARAM 's=500M,h=500M,v=0x1ff'
> Is there some way to do this from inside the OCaml program?  I don't 
> see anything in a quick look at the documents for GC.

Look for "minor_heap_size" and "verbose" in the "control" record type.
As for the initial heap size, of course it cannot be set from inside
the program, but "major_heap_increment" will do in this case.

Reference: < >

OCaml troll on Slashdot


Spawning a huge thread, Karl Zilles said:
Jon Harrop said, Yoann Padioleau asked, and William D.Neumann answered:
> > I spent a little time on it but some Anonymous Coward has already done a much 
> > better job and posted the resulting code on Jacques Garrigue's website. ;-)
> where ?
Jacques Garrigue said:
Well, since it seems difficult to hide that I'm an anonymous coward,
I add a few comments for the list.

Yoann Padioleau wrote:
> Yes but this ocaml code use array ?
> In that case it supports what the "troll" said, that is
> the resulting code is no more "functionnal".
> I agree with eijro sumii that ocaml is not just about functionnal
> programming but in the mind of many people advocating ocaml is advocating
> functionnal programming.
> I think the way to answer to those trolls is to teach them the way
> to do, in that case to use Map instead of associative list, and
> not to be pretentious and to tell that he is just a newbie.
> He is not a newbie, this garden optimization problem is not that simple.

In this particular case, I believe the trouble is rather that the
problem is really geared toward a specific solution. Efficient
memoization requires efficient access to memoized results, which in
this case can be obtained by mapping states to integers. And there
happens to be a trivial mapping. Then any solution will have to
iterate on the states.

If you look at my translation, I do not mutate arrays (except for
memoization), and use no references. That is, the mapping from states
to integers is actually produced in a purely functional way, and
arrays are only there to provide O(1) access. Moreover state
representation uses lists and natural sharing, so that it is
reasonably space efficient.
I also use lists, pattern matching, and recursion, so I believe this
fulfills his requirement about being written in functional style.

Out of curiosity, I also wrote a purely functional version, where
memoizing is done through an array of lazy values.
The code is actually slightly shorter. Performance is rather close.
On a Pentium M 1.8, for a 8x8 garden, I obtain (including memory usage)
   Garden.cpp  5.8s  6.1MB (g++ -O)
   Garden.cpp  4.5s  6.2MB (g++ -O3)  5.9s  8.3MB (ocamlopt)  10s   27.4MB (ocmalopt)
So you can see that garden2, while being almost purely functional,
is really equivalent in performance to his C++ code (which is a bit
dumb, but garden2 doesn't try to be more clever), while garden3 uses
more memory (as expected).

The only thing this example shows is that writing in a functional
language doesn't dispense you of doing a complexity analysis. In
particular the use of structural equality and association lists may
cost a lot in practice.
Some people may have a mystical belief that the compiler will
automatically improve your code through program transformation, but at
least in ocaml the situation is simple: the compiler does no
transformation whatsoever, so you get what you write.
And of course, SICP is a good reading before starting to write
in a functional programming language; I suppose all the structures I
used are explained there in detail.

Help on Event module wanted


Matthieu Dubuget said:
I asked a question related to Event usage there:

and Rémi Vanicat answered with clean explanations:

demexp 0.4.0


David Mentre announced:
I'm pleased to announce the availability of stable release 0.4.0 of
demexp. Of course, demexp is programmed in OCaml.

What is demexp?

demexp is a client/server system for direct democracy. It makes it
possible to ask questions in the system, add new answers to those
questions, and vote on proposed answers. The voting procedure used is
Condorcet voting. Questions are classified, and a delegation system (not
yet implemented) allows one's vote for certain questions to be assigned
to a chosen delegate. The software is tailored to the needs of the
Democratic Experience project.

What's new since latest annoucement[1]?

Since last september we have added:

 - a nice graphical client using lablgtk2 toolkit;

 - save/load of server base in XML format using CDuce;

 - redesign of classification system;

 - disabling of delegation;

 - various bug fixes to make it usable.

demexp can now be used for testing purpose in small groups. 

What about the future?

We know that the client is far from perfect and we plan to improve it in
the short term.

After that, we plan to do (in probable order): delegation;
internationalization and localisation; security.

*We are still looking for motivated OCaml developers.* :)

Where can I get a client?

Source code:

Linux binary:

Debian package:

Windows binary:

Side note: in all above sites, client 0.3.8 or 0.3.9 is similar to

How can I test it?

A demonstration server is available at:
 port: 50000

A demonstration account:
 login: demo
 password: demo

Let me know if you want to have your user account.

Web links

Development website:

The democratic experience project:

Tail Recursion on Map, Append, etc.


Tyson Whitehead asked:
I was wondering about the status of map and friends with regard to tail
recursion.  There was a big discussion back in 2003 about specific solutions 
(implementation of the those functions using Obj) and more general compiler 
support for holes/destination passing.  It started with the following 

It sounded to me like the general consensus was to immediately implement the 
specific tail recursive versions of these functions for List and friends 
(which were provided in the discusion), and then improve the compiler by 
adding support for advanced hole/destination passing solutions.

Looking at the list implementation in the OCaml Debian unstable source, it 
doesn't look like the more efficient version has been implemented.  Further, 
looking at the assembler emitted for the code it doesn't look like the 
compiler supports holes/destination passing either.

January 2003 was quite a while ago, anybody know what's up here?
Richard Jones answered:
The extlib implementations are supposedly all tail-recursive.
Jacques Garrigue also answered:
> It sounded to me like the general consensus was to immediately implement the 
> specific tail recursive versions of these functions for List and friends 
> (which were provided in the discusion), and then improve the compiler by 
> adding support for advanced hole/destination passing solutions.

The result of this consensus is the extlib library. It provides those
tail-recursive functions.
There is no project to include specific support in the compiler, but
the extlib implementation shows that this is not required if a bit of
magic is permitted.

Note that this list is not the core developers list, so the result of
discussions here does not imply anything on the ocaml distribution

> Looking at the list implementation in the OCaml Debian unstable source, it 
> doesn't look like the more efficient version has been implemented.  Further, 
> looking at the assembler emitted for the code it doesn't look like the 
> compiler supports holes/destination passing either.

To correct a misunderstanding: tail-recursive versions are not
necessarily more efficient (at least on short lists; short meaning
less than 10000 elements), but they are safer.
Non tail-recursive functions are carefully marked in the list module,
and alternative functions are included.
For instance:
  let safe_map f l = List.rev (List.rev_map f l)
  let safe_append l1 l2 = List.rev_append (List.rev l1) l2
provide you with tail recursive versions of map and append.
In practice they perform relatively well, if you don't want to
download extlib.

a tiny ocaml/ocurl program for frequent flyers (on United Airlines)


Eijiro Sumii announced:
I've written a simple OCaml script (using OCurl) that detects
seat/schedule changes of your flights on one particular airline (guess

In case anybody (other than myself) uses this program, please let me
know whether it works - it is a little hard to test because it
requires real reservations and changes!  (It worked for me at least a
few times in the last several months.)

If you don't understand why such a thing is useful, either (A) you
don't fly much, (B) you are _so_ patient that you don't feel much pain
when sitting in a non-bulkhead economy-class seat for 14 hours, (C)
you are rich enough to fly in business/first class without winning the
waitlisting competitions for free upgrades, or (D) you haven't yet
discovered the crazy world of frequent flyers.;-) In the last case,
you would have some fun by taking a look at


for example.

Objective Caml 3.08.3


Damien Doligez announced:
We have the pleasure of announcing the release of

              Objective Caml version 3.08.3

This is mostly a bug-fix release; see below for the list of
changes.  Upgrading is not urgent unless you have problems with
one of the bugs listed below.

Please note that we do not guarantee binary compatibility with
previous versions (including 3.08.2).

Only the source is available for the moment.  We will provide some
binaries in the near future.

It is available at

-- Damien Doligez for the Caml Team

Objective Caml 3.08.3:

New features:
- support for ocamlopt -pack under Mac OS X (PR#2634, PR#3320)
- ignore unknown warning options for forward and backward compatibility
- runtime: export caml_compare_unordered (PR#3479)
- camlp4: install argl.* files (PR#3439)
- ocamldoc: add -man-section option
- labltk: add the "solid" relief option (PR#3343)
- compiler: ocamlc -i now prints variance annotations

Bug fixes:
- typing: fix unsoundness in type declaration variance inference.
     Type parameters which are constrained must now have an explicit 
     annotation, otherwise they are invariant. This is not backward
     compatible, so this might break code which either uses subtyping or
     uses the relaxed value restriction (i.e. was not typable before 
- typing: erroneous partial match warning for polymorphic variants 
- runtime: handle the case of an empty command line (PR#3409, PR#3444)
- stdlib: make Sys.executable_name an absolute path in native code 
- runtime: fix memory leak in finalise.c
- runtime: auto-trigger compaction even if gc is called manually 
- stdlib: fix segfault in Obj.dup on zero-sized values (PR#3406)
- camlp4: correct parsing of the $ identifier (PR#3310, PR#3469)
- windows (MS tools): use link /lib instead of lib (PR#3333)
- windows (MS tools): change default install destination
- autoconf: better checking of SSE2 instructions (PR#3329, PR#3330)
- graphics: make close_graph close the X display as well as the window 
- num: fix big_int_of_string (empty string) (PR#3483)
- num: fix big bug on 64-bit architecture (PR#3299)
- str: better documentation of string_match and string_partial_match 
- unix: fix file descriptor leak in Unix.accept (PR#3423)
- unix: miscellaneous clean-ups
- unix: fix documentation of (PR#3341)
- graphics: fix problem when allocating lots of images under Windows 
- compiler: fix error message with -pack when .cmi is missing (PR#3028)
- cygwin: fix problem with compilation of camlheader (PR#3485)
- stdlib: Filename.basename doesn't return an empty string any more 
- stdlib: better documentation of Open_excl flag (PR#3450)
- ocamlcp: accept -thread option (PR#3511)
- ocamldep: handle spaces in file names (PR#3370)
- compiler: remove spurious warning in pattern-matching on variants 
- windows: better handling of InterpreterPath registry entry (PR#3334, 
Aleksey Nogin said:
I have compiled RPM packages of OCaml 3.08.3 :
- Fedora Core, all releases (1, 2, and 3)
- Red Hat Linux 8.0
- Mandrake 10.0
- Source RPM

Download them from
Sven Luther said:
Well, Debian packages should be in experimental in a bit, pending a full
rebuild of the 50+ ocaml-related packages which should take us a couple of

Release of Numerix-0.21


Michel Quercia announced:
The new Numerix release is available at the following URL:

Numerix is a big integer library designed for a use with the Caml-Light and 
Ocaml languages (among others). This new release implements faster algorithms 
for very big integers (with several thousands bits or more) as well a SSE2 
machine code for Pentiums >= 4 roughly twice as fast as the standard x86 
machine code. Numerix-0.21 was sucessfuly tested with the following Operating 
Systems :

  Linux-PC, processors AMD-Athlon and Pentium-4
  OpenBSD-PC, processor i386

I want to thank here Mark Shields for his great help in the Mac-OSX port.

Numerix-0.21 is expected to run on any Unix system similar to one of those, at 
least with the Clong version (this is standard C code). The machine code 
version (module Slong) if only available for x86 processors.

Documentation :

Sandboxing in ocaml


Christian Szegedy asked and Jacques Garrigue answered:
> Is this possible in ocaml to dynamically load some (bytcode) OCaml file 
> and run it in a safe environment, that is only using a small subset of 
> selected functions instead of the whole Pervasives?

This is the intent of Dynlink.allow_only.
Not however that allowing is done on a unit base, so if you want to
allow only some functions in a unit, you must create a new one
containing only those, and compile your file against those (otherwise you
won't be able to load it).
This is the way MMM applets are made safe.

Also, there is no bytecode verifier. That is, a hand-crafted bytecode
file could break the above safety. In this respect, the bytecode
interpreter does not provide real sandboxing. If you want to protect
yourself, you have to use other ways, like a certified signature
scheme. The following paper explains this strategy to safety:
 Xavier Leroy and Francois Rouaix. Security properties of typed
 applets. In J. Vitek and C. Jensen, editors, Secure Internet
 Programming - Security issues for Mobile and Distributed Objects,
 volume 1603 of  Lecture Notes in Computer Science, pages
 147-182. Springer-Verlag, 1999.
Christian Szegedy then asked and Jacques Garrigue answered:
> Excellent! This sounds exactly what I want. Can I forbid
> the Pervasives unit while linking the applet?

Sure: just omit it from the allowed units.
The applet should then be compiled with the -nopervasives option.

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