Previous week Up Next week


Here is the latest Caml Weekly News, for the week of 26 October to 09 November, 2004.

  1. *s ignored on windows gui
  2. New Mailing List- Ocaml Licensing
  3. GODI news
  4. SwfLib Release
  5. Pattern matching but no construction?
  6. Library for handling Gregorian date calculations
  7. Pervasives 'general output functions'
  8. Mozcaml bar contents updated
  9. Camomile 0.6.1
  10. surreal is resurrected
  11. Ochra - Reference Attributed Grammars in OCaml
  12. Scheme added to Felix compiler
  13. native code and ZINC machine
  14. 64-bit OCaml?
  15. Print values like the toplevel's printer

*s ignored on windows gui


Tiago Dionizio asked:
I was playing with ocaml (learning!) and bumped with something that i
think it might be a bug... since i didn't find anything explaining
this behaviour:

Objective Caml version 3.08.0

# print_string "**e";;
e- : unit = ()
# print_char '*';;
- : unit = ()

it seems that the '*' char is ignored at the beginning of the lines on
the windows gui, the same does -not- happen on the command line

Is this a known problem? Sorry if this was reported already or if it a
known issue.
Christopher A. Watford fixed the problem and replied:
As always, if you want the bleeding edge of OCamlWinPlus, I suggest
you check out (that is my actual VS.Net project directory):

If you'd like the more stable side of the bleeding edge (stable
directory on my webserver that only takes polished copies):

New Mailing List- Ocaml Licensing


Brian Hurt announced:
I've created a new mailing-list/yahoo group ocaml-licensing, for a 
discussion of the pros and cons of various licenses for Ocaml code.  The 
URL is here:

Or send email to:

There is now an official elsewhere to take this dicussion.  Thank you.

GODI news


Gerd Stolpmann announced:
The GODI project has a new homepage explaining how to install and use
the source code O'Caml distribution:

Highlights are:

- An online version of the new GODI manual
- Lists with available packages
- Collection of the most important O'Caml links

The new GODI manual is also available as GODI package godi-manual. It
explains almost every aspect of the GODI installation in detail.
Furthermore, there is also documentation of package creation (with the
GODI core method; GODIVA is not (yet?) explained).

I hope the homepage and the manual make GODI a bit more transparent, and
also more attractive.

SwfLib Release


Nicolas Cannasse announced:
I'm please to announce the first release of SwfLib, a pure OCaml library for
parsing, manipulating, and writing SWF content. SWF is the file format used
by Macromedia Flash Player and available on most users browsers. It contains
a vector draw engine with bitmaps support and have a simple stack based
virtual machine for a dynamic OO scripting language called ActionScript.
SwfLib can both produce the graphics and the bytecode needed to build a SWF
binary file.

SWFLib source code is released under GPL, and is currently only available on
CVS using the following CVSROOT :

cvs -d co ocaml/swflib

With empty password.

Pattern matching but no construction?


John Harrison asked and William Lovas answered:
> Is there a way to use the OCaml module system to declare an
> abstract type with an implementation as a recursive type in
> such a way that:
>  * You can use the constructors to pattern-match against
>  * You cannot use the constructors to construct values

Indeed, there is!  The relevant keyword is `private'.  See:

for details.

> For example, suppose I do the following:
>   module type Wibble =
>     sig type thing = Integer of int | Boolean of bool
>         val mk_thing : int -> thing
>         val dest_thing: thing -> int
>     end;;
>   module Thing : Wibble = struct
>     type thing = Integer of int | Boolean of bool
>          let mk_thing i = Integer i
>          let dest_thing t = match t with
>            Integer i -> i
>          | Boolean b -> if b then 1 else 0
>     end;;
>   include Thing;;
> I can now define functions by pattern-matching, which I want:
>   fun (Boolean b) -> b;;
> but I can also use the constructors to construct, which I don't:
>   Integer(3);;
> On the other hand, if I change the signature to just
>   module type Wibble =
>     sig type thing
>         val mk_thing : int -> thing
>         val dest_thing: thing -> int
>     end;;
> then I can do neither. Is there any way to get one and not the
> other?

In your example, we just do:

> For example, suppose I do the following:
>   module type Wibble =
>  (* sig type thing = Integer of int | Boolean of bool *)
      sig type thing = private Integer of int | Boolean of bool
>         val mk_thing : int -> thing
>         val dest_thing: thing -> int
>     end;;
> [...]

And then it works as expected:

    # Thing.Integer 5;;
    Cannot create values of the private type Thing.thing
    # let thing = Thing.mk_thing 5;;
    val thing : Thing.thing = Thing.Integer 5
    # match thing with
        Thing.Integer i -> i
      | Thing.Boolean b -> 0;;
    - : int = 5

Library for handling Gregorian date calculations


Following this library announcement, the following took place:
Owen Gunden wrote:
> Julien Signoles wrote:
> > Richard Jones wrote:
> > > I'm pleased to announce GregorianDate [...]
> > 
> > What are the differences with the module Date of the "calendar" library ?
> > 
> >
> I've a stake in this question too, as the maintainer for the calendar
> godi package.  It sure would be nice if the effort was merged into one
> UberCalendar so there would be no question which package to use.

Ah, sorry - this discussion moved to ocaml-lib-devel.  I cc'd
caml-list, but it seems to have been spam filterered.

Pervasives 'general output functions'


Diego Olivier Fernandez Pons asked and Nicolas Cannasse answered:
> I would like a Caml program to output some information to an output
> channel and according to my needs this channel be redirected to
> - a (human readable) file
> - the standard output
> - a black hole
> The "general output functions" section of Pervasives seem to be what I
> need but it hasn't the same signature than "Output functions on
> standard output"

Generic IO from ExtLib are dealing with this problem, and have a printf
They also have useful functions such as  write_i16 / write_ui32 .... (in low
and big endian) when dealing with C binary files.

> I suspect I could just compose with string_of_X functions to obtain
> the same result. There is also an awful [fprintf] function inherided
> from C but I am still trying to understand the doc (never understood
> C's either).

printf "%d %f %s %c"  33 1.234 "hello" 'x'

> Why haven't the equivalent functions been added to the standard lib to
> allow a drop in replacement ?

Maybe because printf allows you to specify precision for int/floats as well
as newlines ?

Mozcaml bar contents updated


Maxence Guesdon announced:
The contents of the Mozcaml sidebar has been updated (at least!) for ocaml

Mozcaml is a sidebar for Mozilla dedicated to the Caml language.
It provides direct access to many information about Objective Caml: news, user's
manual, library documentation and the humps (the collection of links to
Caml-related stuff). Each of these sources can be browsed throughout several
views, including contents tree, indexes or search engines.


Camomile 0.6.1


Yamagata Yoriyuki announced:
Camomile 0.6.1 is released.  This release is intended to be a bug-fix
only release.  Fixed bugs are

* the bug that "get" methods of polymorphic input channels have
the type 'a, which should be unit -> 'a.
* a bug which causes flush methods of octet output channels only
flush 1024*n bytes at a time.
* Remove a superfluous check from configure.

You can download the new release from

Our Web page is

Please submit your bug report to the bug tracker.

GODI version will be released in the next days.

Camomile is a Unicode library for ocaml. Camomile provides Unicode
character type, UTF-8, UTF-16, UTF-32 strings, conversion to/from
about 200 encodings, collation and locale-sensitive case mappings, and

surreal is resurrected


Yamagata Yoriyuki announced:
Surreal library is again available from

Unfortunately, no improvement has been possible (yet).  Logarithm and
reverse triangular functions are not implemented.

Surreal library is an exact real arithmetic library for OCaml.  The
goal is to do middle-scale computation with 500-2000 operands to exact
reals in the reasonable amount of time.  To that goal, surreal uses
some heuristics to evaluate the value of reals, with optimized
algorithms for transcendental functions.  By using Numerix, surreal
avoids memory allocation overhead, since Numerix uses OCaml heap
allocator and GC directly for all memory management

Ochra - Reference Attributed Grammars in OCaml


Martin Sandin:
I'm pleased to announce that the first release of
Ochra, v0.1, is now available. The release and
information is available at:

Ochra is a syntax extension for OCaml, extending the
language with explicit support for programming using
an Object-Oriented Reference Attributed Grammar (RAG)
formalism. The primary intended use is for compiler
construction. It introduces a new kind of classes,
called productions, which support a number of extra
features for specifying AG node children and
attributes. Ochra is modeled on JastAdd, a compiler
construction tool which extends Java. Ochra is however
a less intrusive addition than JastAdd, which along
with RAG support also introduces Aspect Orientation in
Java. Ochra instead relies on the more powerful
modularization mechanisms of OCaml (multiple
inheritance, structural subtyping, parametrized types
and modules, ...), compared to Java, to provide the
same level of modularity.

JastAdd has been used to construct, among other
things, a Java compiler and is used in compiler
classes at Lund Institute of Technology.

Comments are ofcourse appreciated:)

Ochra is released under the LGPL license with the same
exceptions as for the OCaml libraries.

Scheme added to Felix compiler


John Skaller:
I have just uploaded a revised tarball for  Felix 1.0.18.
Felix is open source with BSD style FFAU licence.

This version now incorporates the Scheme interpreter
ocs-1.0 in the compiler. Ocs was 
written by Ville-Pertti Keinonen <>
and the original source can be obtained from

A scheme reference can be found at

The interpreter is available standalone tool
(called 'ocs_main' at the moment, but the name will 
probably change)

It can also be used with the Felix preprocessor. 

#scheme (display "//generated by scheme\n")
#scheme (load "somefile.sch")

The environment is currently shared across
directives and include files so variables set
in one place can be used in subsequent places.

The #scheme directive is replaced by whatever it
writes to standard output, and is then
tokenised as if it were Felix code.

In future releases I may add system variables
and utilities to the environment, and perhaps
extend the interpreter so it can access some of
the compiler state. I will be examining whether
it is feasible to invert the control relation
of the front end so it's a scheme program
embedding Ocaml (rather than the other way arond).
This may help to make user control and extensions
easier to script.

native code and ZINC machine


Aaron Bohannon asked and Xavier Leroy answered:
> I was quite surprised, recently, when I found out that the native code 
> compiler implements left-to-right evaulation, as opposed to the 
> right-to-left evaulation of the bytecode.

This isn't quite right.  The native-code compiler is essentially
neutral w.r.t. evaluation order, meaning that it can implement any
given evaluation order without singificant changes or performance
impact.  However, following the principle of least surprise, it tries
to enforce the same evaluation order as the bytecode compiler, that
is, right-to-left.  

There is one mistake in 3.08 (corrected in the main branch) that causes
left-to-right evaluation for arguments to certain inlined functions
(see PR#2910).  If you observe left-to-right evaluation with ocamlopt,
please report it.  It's not really a bug according to the OCaml manual
(which leaves evaluation order undefined), but it's certainly a
"quality of implementation" issue that we'd like to be aware of.

> You see, I am quite familiar with the ZINC machine and the benefits of 
> its design, and I thought that the design could be adapted in some way 
> or another to the native code setting.  I am interested in finding out 
> what factors prevented this, or what made the ZINC machine execution 
> model impractical in the native runtime.  My knowledge of systems is 
> perhaps somewhat weak, so maybe I am overlooking some obvious point.

The ZINC / OCaml VM handling of curried function application (an
instance of the push-enter model) pretty much requires that parameters
are passed on a stack.  For native code generation, it is much more
efficient to pass the first N parameters in processor registers.  This
doesn't fit the ZINC model at all.

64-bit OCaml?


David McClain asked and Xavier Leroy answered:
> I just obtained a new iMac G5 here. My cursory understanding is that this is
> a 64 bit core processor. However, when I attempted to run config for
> rebuilding the OCaml system, it reports a 32 bit system. What can or must I
> do to coax OCaml to become a 64 bit system for this processor?

As others have explained, the first thing you need is a 64-bit kernel
and a development environment (C compiler, linker, libraries) that
handles 64-bit code.  The next release of Mac OS X is rumored to offer
all this.

Once this is available, you should be able to compile the bytecoded
part of OCaml to 64-bit code using e.g. configure -cc "gcc -m64"
or whatever gcc options that select the generation of 64-bit apps.

However, ocamlopt will not work out of the box.  Some changes to the
asm code generator are required to produce 64-bit code.  In the case
of the PowerPC, the changes are relatively small.  Still, I can't
perform them until we have G5 machines at INRIA, which may take a while.
(Pretty much the only Apple hardware we buy are Powerbooks, and it's
unclear when G5 Powerbooks will be mainstream.)

Also, the only situations where 64-bit code is beneficial are 1- large
integer arithmetic (bignums, crypto), and 2- exploiting more than 4 Gb
of RAM.  In all other cases, 64-bit code is actually a waste,
since pointers occupy twice as much memory as with 32-bit code.

So, I expect 64-bit computing to take off when machines commonly have
4 Gb of RAM or more, which should take a few more years.  Caml will
have no problems adapting to this trend, since it's 64-bit clean from
the start.  (Caml Special Light, the ancestor of OCaml, was developed
circa 1995 on a 64-bit Alpha, then backported to 32-bit
architectures.)  I expect that at that time our "tier 1" architectures
will be x86-64 and PPC-64.

Print values like the toplevel's printer


Wolfgang Müller asked and Yoann Padioleau answered:
> I would like to print values to a file in a human-readable manner without
> having to compose the output writers of print_int and friends. In short, I
> would like to use the toplevel's function for screen output of structured
> values.

I recently post a message to allow this (with generic print in the subject
of the message).

the code is available at:

  let _ = print_string (generic_print [[1;3];[2;9;8];[3;4]] "int list
list" in
  let _ = print_string (generic_print [1;3;2;9;8;3;4] "int list") in

   [[1; 3]; [2; 9; 8]; [3; 4]]
   [1; 3; 2; 9; 8; 3; 4]
Daniel Bünzli added:
Although research oriented you may want to have a look at acute, an extension
of an ocaml core to support, among other things, type safe value IO :

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