Previous week Up Next week


Here is the latest Caml Weekly News, for the week of October 21 to November 11, 2008.

  1. ocamlbuild-ctools and symbiosis meta build engine
  2. camlish: a simple module for shell scripting in OCaml
  3. Mlpost 0.5
  4. Yacfe 0.2
  5. OCaml meeting 2009 in Grenoble
  6. camlp4
  7. OCaml-Java project: 1.1 release
  8. OCaml Batteries Included alpha 2

ocamlbuild-ctools and symbiosis meta build engine


Mikkel Fahnøe Jørgensen announced:
There is a tutorial online (and in the source) now and two examples in
the source tree.

The examples are created during the tutorial.

The tutorial also creates a more complex setup with source control
which is not possible include in the example tree due to the
configuration involved.

symbiosis v0.1.1 adds the tutorial and basic git and wget supported -
both used in the tutorial.

The three tools now have a home page:

or just

camlish: a simple module for shell scripting in OCaml


Zheng Li announced:
I'd like to announce the availability of a small module for shell scripting:

The project URL is:, where you can
get all the code and docs. A source repo is going to provide later.

It's rather experimental, bug reports are always welcome.

Have fun!

FYI, the rest parts are directly copy&pasted from the README file:

===== Motivation =====

I was thinking about using OCaml for shell scripting. I once looked at
Cash, but quickly went away: I didn't really want to read 100+ pages of
manual just for my little scripting purposes. Recently there came
Caml-Shcaml, it also successfully stopped me from exploring any further
with its ~700 APIs (Sure I believe learning a small portion of them can
be enough to get me a quick start, but still...)

I believe they are both excellent and full-fledged shell
implementations, but they are really overkilled for me. Vanilla OCaml is
already a full-functional language which I can do anything with, include
scripting. What I want is just a little more convenience on this aspect,
better with minimal learning cost, not to learn another "language".
Otherwise I could just resort to plain ocaml because I'm lazy. Moreover,
I don't want to patch my compiler source or use Camlp4 magic to have a
more shell-like syntax: it's probably nice-looking but alien.

==== Basics ====

So I wrote camlish, a plain OCaml module to ease shell scripting in
OCaml, especially for those thinking the same.

Camlish follows simple principles:

 * It deals with simple coordination and interaction with outside
   commands and shells. It provides a very thin layer of glues to
   ease that. That's all it does.

 * OCaml itself has far better language features than any shell
   script languages out there, so when camlish is used for scripting,
   it encourages you to stay on the OCaml side as much as possible,
   call external and push/pull the inputs/outputs back/forth as OCaml
   values, and sometime resort to /bin/sh if necessary.

==== Features ====

Here are some features of camlish:

 * Code base is small. The core is just 500+ loc, 30+ definitions
   (except operator sugar).

 * Interface is simple. It deals and only deals with the follows:

   - command construction: wrap a string or a OCaml function to a
     typed command

     <code ocaml>
     let c1 = cmd "seq 1 20"                    (* (unit, unit) cmd *)

     let c2 = func ( float_of_int)
                                      (* (int list, float list) cmd *)

   - command redirection: redirect input/output/error to any files,
     file descriptors and OCaml values, via plain record syntax. We
     call all these direction adapters as "ports". Besides a number
     of primitive ports, we can define and compose our own "ports"
     for any data type.

     <code ocaml>
     let c3 = { c1 with pout = pout_lines }
     	       	    	      		  (* (unit, string list) cmd *)
     let c4 = { c2 with pin = int_of_string =| }
                                   (* (string list, float list) cmd *)

   - command composition: pipeline(>>>), sequence (&&&) and
     subshell(~$) and more.

     <code ocaml>
     let c5 = c3 >>> c4                    (* (unit, float list) cmd *)
     let c6 = {(cmd "pwd" &&& cmd "date") with pout = pout_file "log"}
                                                 (* (unit, unit) cmd *)

   - command execution: input/return values according to command's
     redirection. There are different execution schemes depending on
     various factors (e.g. having input value or not, running in
     background or not etc.)

     <code ocaml>
     !! c5                          (* get float list [1.; ...; 20.] *)

     The example is made up for illustration. In practice you'd
     instead write

     <code ocaml>
     !! { (cmd "seq 1 20") with pout = pout_lines |= float_of_string }

     and commands without redirection look normal:

     <code ocaml>
     !! (cmd "ls -l" >>> cmd "wc -l")
     !$ "ls -l | wc -l"                    (* resort to /bin/sh pipe *)

     Here is an example collaborating commands and functions to count
     the numbers x between 1 .. n where x mod 3 or 5 is 0.

     <code ocaml>
     let count n=
       { (cmd "seq 1 %d" n) with pout = pout_lines }
       >>= int_of_string
       >>- List.filter (fun x -> x mod 3 = 0 || x mod 5 = 0)
       >>> {( cmd "wc -l") with
              pin = string_of_int =| pin_lines;
              pout = pout_string |- int_of_string }
                                        (* int -> (unit, int) cmd *)

     !! (count 1000)                     (* return OCaml int: 466 *)

     Please read the manual for more details.

 * The interaction between external commands and OCaml values are
   implemented asynchronously inside (but with a synchronous
   interface). So it won't get stuck unnecessarily when dealing with
   large chunk of input/output.

   Moreover, a pair of stream ports are provided, so that you can
   read/write "not fully available" or infinite string/data on
   the borders of OCaml and commands. E.g.

   <code ocaml>
   let s = !!. { (cmd "yes") with pout = pout_stream "\n" }
                                (* the endless output of "yes" is
				    redirected to a stream value. *)

   let _ = Stream.iter print_endline s     (* print infinite "y" *)

 * It's tempting to use Camlp4 or to modify the compiler in order to
   achieving terse shell-like syntax, but we choose not. Camlish is a
   plain OCaml module.

 * It's also tempting to implement simple versions of common unix
   tools such as "ls" and "grep" as OCaml functions to achieve better
   composability. We opt not for the core module and not for now.

 * Camlish supports RC file written in OCaml, i.e. when you load
   camlish module from toplevel or run customized toplevel with
   Camlish embedded, it will try to read a file named ".camlishrc"
   from the current working directory firstly and the home directory
   of current user secondly. The RC file can be any plain ocaml file,

   <code ocaml>
   open Camlish
   open List
   open Prelude
   module A = Array
   module S = String
   module U = Unix

 * When used interactively, camlish can additionally execute shell
   commands directly. So we can now use the toplevel as a shell,
   feeding it ocaml phrases and shell commands at the same time.

   Here is a trace of record:

   <code ocaml>
   $ rlwrap camlish   (* Or rlwrap ocaml unix.cma camlish.cma *)

          Objective Caml version 3.10.2

   [1] ls -l | wc -l;;
   - : unit = ()
   [2] date;;
   Sat Oct 25 12:06:51 CEST 2008
   - : unit = ()
   [3] let f x = x;;
   val f : 'a -> 'a = <fun>
   [4] f 100;;
   - : int = 100
   [5] for i in `seq 1 3`; do echo "Now: "$i; done;;;
   Now: 1
   Now: 2
   Now: 3
   - : unit = ()
   [6] emacs -nw;;

   In case there is some ambiguity, e.g. a OCaml value shadows a
   command name, a ";;;" ending can be used to enforce it is a
   command instead of OCaml toplevel phrase.

Please refer to the manual for more details.
Sylvain Le Gall then suggested:
>    * It's also tempting to implement simple versions of common unix 
>      tools such as "ls" and "grep" as OCaml functions to achieve better 
>      composability. We opt not for the core module and not for now. 

You should take a look at

Where you already have a basic implementation for ls, find, touch, rm, 
cp, du, cmp... These are pure OCaml functions, that you can call directly 
from OCaml (not external call).
Mikkel Fahnøe Jørgensen also replied, and Zheng Li said:
> Great!, but bummer, I wrote one too last night....
> Also looked at FileUtils and ShCaml, but wanted something light.
> Anyway - it seems orthogonal to mine.
> I don't do any pipeline processing, I just make it easy to cp, mv,
> etc. using ocaml toplevel scripts as an alternative to install
> scripts.

I just had a visit to your project, and yes, I agree they are mostly
orthogonal. Camlish only concentrates on the interaction, redirection,
composition and coordination of _external_ commands, pushing/pulling the
input/output as OCaml values. It doesn't, and probably won't, define
functions as common shell commands by itself, which, I believe, are
better left to other libraries.

As a compensation, camlish allows one to execute shell commands directly
from toplevel, if (s)he doesn't care about the interaction with OCaml
world. So instead of writing

 # !! cmd "ls -l";;

which is plain OCaml function calling outside command "ls", one can
simply write

 # ls -l ;;

which is a shell command, not a function named "ls". I myself am
interested in using OCaml toplevel as a shell environment.

Still, it's very nice to see others confronting similar problems and
trying to solve them in different approaches.

Mlpost 0.5


Jean-Christophe Filliâtre announced:
We are pleased to announce the first release of Mlpost, an Ocaml
interface to MetaPost, a powerful software to draw pictures to be
embedded in LaTeX documents.

Mlpost is free software under LGPL license and is available at

Some examples are available online (thanks to Martin Jambon's caml2html):

You can have a look at Mlpost's API online:

Have fun with Mlpost,

the Mlpost authors,
Romain Bardou, Johannes Kanig,
Stéphane Lescuyer and Jean-Christophe Filliâtre

Yacfe 0.2


Yoann Padioleau announced:
I am pleased to announce the first release of Yacfe, Yet Another C/C++
Front-End, which is an OCaml API to write style-preserving source-to-source
transformations such as refactorings on C or C++ source code.

The goal of Yacfe is to parse the code as-is, and to represent it
internally as-is. Yacfe thus maintain in the abstract syntax tree (AST)
as much information as possible so that one can transform this AST and
unparse it in a new file while preserving the coding style of the
original file. Yacfe preserves the whitespaces, newlines, indentation,
and comments from the original file, as well as the C preprocessor
(cpp) macros and cpp directives. 

Other source-to-source transformation tools such as CIL [1] do not
preserve this coding style as they first call cpp on the original file
and perform the transformation on the preprocessed file. The AST of
Yacfe on the opposite contains explicit constructions representing cpp
directives, macro definitions, or cpp idioms such as macro iterators
as in 'list_for_each(i, x) { printf("%d", x); }'. "What You See In The
Yacfe AST Is What Was Written". The Yacfe abstract syntax tree is thus
in fact more a concrete syntax tree (cf parsing_c/

Yacfe is free software under GPL license and is available at

A simple example of the code of a style-preserving program transformation 
using the Yacfe API is available here:

If you want to do fancy static analysis on C code, use CIL [1], it is
better equiped for that task, more robust, more mature. If you want to
do style-preserving source-to-source transformation, well, you may
find Yacfe useful.


PS: Yacfe was extracted from the code of the Coccinelle project for Linux device drivers
evolutions. Yacfe was supported mainly by money from l'Ecole des 
Mines de Nantes as well as money from the University of Urbana-Champaign.

OCaml meeting 2009 in Grenoble


Sylvain Le Gall announced:
For the second time, I am proud to invite all OCaml enthusiasts to join
us at OCaml Meeting 2009 in Grenoble.

This year event will be in Grenoble just after JFLA. We choose this
location because a lot of OCaml enthusiasts will probably already been
there and to avoid last year collision between the two events.

As last year, participants are invited to give a talk on what they are
doing with OCaml.

The meeting will be partly sponsored by OCamlCore. Participation will be
used for the lunch.

Volunteer to help before/during the event can contact me directly.

Further information:

For people who need further information, you can contact either me or
Alan Schmitt (see for contact details).

Hope to see a lot of you
Sylvain Le Gall on behalf of the OCaml Meeting organization team.



Anastasia Gornostaeva asked and Richard Jones answered:
> How can I learn modern Camlp4?

With difficulty.  That's sad because it's very powerful.

I would suggest starting with Martin's Jambon's tutorial.  Even though
it refers to the "old" camlp4 / camlp5, it's still useful to
understand the concepts:

Then take a look at Martin's example of what changed between the two

The camlp4 wiki has already been mentioned, and is very useful.  This
is probably the most useful reference page of all:

Finally take a look at some real examples:
Jon Harrop also replied:
The new Camlp4 is not yet fully documented. The official documentation is on a 
wiki here: 

Richard Jones' OCaml tutorial site has a simple "foreach" example: 

Our OCaml Journal published an article about parsers and macros using the new 
Camlp4 on 23rd November 2007: 

I once posted a simple compiler for the "Minim" language that was written 
using Camlp4:

OCaml-Java project: 1.1 release


Xavier Clerc announced:
This post announces the 1.1 release of the OCaml-Java project.
The goal of the OCaml-Java project is to allow seamless integration of OCaml
and Java.
This version is still based on Objective Caml 3.10.2, the next one will be
based on 3.11.0.

Home page:
Download page:
Toplevel applet:

Main changes since 1.0:
 - move from Java 1.5 to Java 1.6 (will hence not run on a 1.5 JVM)
 - support for JDBC, with automatic generation of bindings to databases
 - support for java.math package
 - Dbm, Servlet, SwiXml and OCamlScripting projects merged into Cadmium
 - experimental support for stack frames
 - bug fixes

OCaml Batteries Included alpha 2


David Teller-Rajchenbach announced:
We are happy to inform you of the availability of OCaml Batteries
Included Alpha 2. This new release introdues numerous bugfixes, more
documentation, numerous new features, speed improvements, a new build
system, a toplevel with on-line help, an optional new toolchain,
on-the-fly gzip (de)compression, better I/O management, more Unicode,

You may download this new version from The Forge [1] or from GODI.
Debian packages are at work. Extended release notes [2] and
documentation [3] are also available on-line. To contact us, please
visit our home page [4].

We hope you find this work useful and consider adopting it for your next
developments with OCaml.

 The OCaml Batteries Included team


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