Previous week Up Next week


Here is the latest Caml Weekly News, for the week of August 23 to 30, 2011.

  1. Job offer: Ocaml/Ocsigen research engineer
  2. OpenGL ES for iPhone Simulator; working example app
  3. Opa released as open source
  4. Ocaml and the Fragile Base Class Problem
  5. insert ocaml source in latex
  6. Ocamlnet-3.4
  7. Other Caml News

Job offer: Ocaml/Ocsigen research engineer


Vincent Balat announced:
Position available: Ocaml/Ocsigen research engineer

The IRILL [3] and the PPS laboratory [2] is hiring a Research Engineer with 
good skills in (Ca)ML programming for 1 year.

Keywords: Ocsigen, Web applications, content management, OCaml

The engineer will join the Ocsigen [1] development team, as
member of the ANR national project PWD (Programmation du Web
Diffus). The work will take place in the new research center on
free/open source software (IRILL) [3] in Paris.

He will participate in the development of various components of
the Ocsigen framework:
 - implementation of higher level tools for creating Web site
   easily (content management, Ocsimore project)
 - extensions and improvements to the Web server
 - library for writing graphical interfaces in OCaml in a browser
 - Ocsigen on mobile phones
 - Ocsigen and cloud computing

About Ocsigen:

Ocsigen is an open source framework to develop client/server Web
applications fully in OCaml, as a single program.

About PPS:

PPS is an A-ranked CNRS laboratory of the University Paris
Diderot Paris 7.  One of its main research topics is the the
study of programming languages and distributed systems and their
logical foundations.  The research activity is associated with an
important software development activity, mainly in OCaml
(for example Menhir, Unison).  The main themes span from the
Web (Ocsigen, CDuce, Xduce, Polipo) to parallel programming (Lwt, OcamlP3L,
CPC), from networks (Babel) to the management of software packages
(Debian, Edos, Mancoosi) and proof assistants  (Coq).

About the IRILL:

The IRILL is a new international research centre on free/open source
software located in Paris. IRILL's objective is to become a reference
center for the research and development of stable and reliable free
software. By hosting development projects, IRILL also acts as an
observatory and experimental centre for transfer using free software.

Required skills:

- Expertise in OCaml programming
- Knowledge of Web standards
- Engineer or PhD degree (master may be sufficient under conditions)

Vincent Balat and Jérôme Vouillon:
{Vincent.Balat || Jerome.Vouillon}


OpenGL ES for iPhone Simulator; working example app


Continuing the thread from last week, Jeffrey Scofield said:
> > I'd be happy to hear from anybody interested in OCaml on iOS.
> Thanks for this - will endeavour to look more closely into it.
> I'm curious as to whether Apple would approve an app written in OCaml
> for the app store. I was under the impression that they wouldn't.

Apple dropped their restrictions on languages for iOS around a year
ago.  The press release is still available here:

We (Psellos) are selling an app written in OCaml in the app store
right now, in fact.  It's called Cassino, and plays a card game.  At
the risk of too much self-promotion, here is a link:

We've had no trouble getting versions of the app approved by Apple.
(Granted, we're not a big enough player to merit a lot of scrutiny.)

When we started porting OCaml to iPhone, it was with the attitude of
doing something slightly crazy, but it has worked out pretty well.
I think OCaml has real advantages for writing iOS apps, and it has
also been more fun and interesting than the usual coding for the
"mobile space".

Opa released as open source


Henri Binsztok announced:
It is our pleasure to announce to the Caml List that Opa is now an open 
source project!

- Opa is a new programming language for writing web/cloud applications. It is 
a functional, statically typed language, with native support for the web. For 
 Create XML fragments values:
 line = <div class="line"></div>
 Access elements of the DOM:

- Opa manages all aspects of a distributed web application (including the 
database) within a single technology and runtime: Just compile Opa code to 
standalone binaries that run the web application server.

- Opa manages client and server code within one language. The compiler 
decides (you can hint) which parts run on the client and on the server, 
automatically generates JavaScript code for the client part and automates all 

- Most of Opa is implemented in OCaml (around 200k LoCs).

We're thankful to the OCaml community for providing such a great technology 
to write Opa and would love your feedback on Opa. We're also setting up a 
Developer Challenge. Submit your application and win some new hardware!

- Opa project home:
- Opa source code:
- Opa developer challenge:

Ocaml and the Fragile Base Class Problem


Chris Yocum asked and Jacques Garrigue replied:
> A friend of mine is giving a talk about "monkey patching" entitled
> "Monkey patching, subclassing, and accidental overriding"
> (
> I was wondering how Ocaml deals with this situation or if it is even a
> problem at all in Ocaml?  I mocked up some code:
> class base =
> object
>  method meth x =
>    print_endline "base";
>    print_endline (string_of_int x)
> end
> class deriv =
> object
>  inherit base
>  method meth x =
>    print_endline "deriv";
>    print_endline (string_of_int x)
> end
> which kind of(?) shows the problem in Ocaml.  He suggests in his paper
> that using a Meta-Object Protocol is the way around this.  What do you
> think?

You can require overriding to be explicit by activating warning 7:

$ ocaml -w +7
        OCaml version 3.13.0+dev6 (2011-07-29)

# class c = object method x = 1 end;;
class c : object method x : int end
# class d = object inherit c method x = 2 end;;
Warning 7: the method x is overridden.
class d : object method x : int end

Note also that in ocaml a method only has one signature,
so the problems with API changes doesn't apply here:
you get an error if the type changed in the base class,
and a warning if the method name was changed in the base class.

However, in this respect I think that a "final" keyword is missing in ocaml.
Namely, you have no way to say that you don't want subclasses to modify
a method (because you want to be able to redefine it yourself, for instance).
But OCaml is not an object-only language, so if you want this kind of
guarantee you can use functors: specify exactly what the user should provide,
without allowing a posteriori overriding.
Gerd Stolpmann also replied:
I think it is a non-issue in practice. Simply because inheritance is
quite seldom in Ocaml, even in programs using a lot of OO features.
There is an attractive alternative, namely passing functions down to
change the behavior of objects. So, you would normally define

class base ?meth () =
  method meth x =
    match meth with
      | None ->
          print_endline "base";
          print_endline (string_of_int x)
      | Some f ->
          f x

class deriv = 
  base ~meth:(fun x ->
                print_endline "deriv";
                print_endline (string_of_int x)

You'd do something like this for all mutable behavior (maybe you
wouldn't use individual functions for overriding, but some more
elaborate data structure). Of course, this is generally a less powerful
technique, but you often don't need the full power of inheritance. This
is attractive for getting more control, and looks less like patching the
algorithms of the base class.

Also, you don't need inheritance in Ocaml for declaring subtyping
relations. So, it is entirely possible to avoid the "inherit" keyword,
and have nevertheless a lot of object-oriented design.
Jacques Garrigue later said:
There are lots of things in this discussion.

A first point I would like to make clear: objects are used in ocaml, and 
quite a lot.
You just have to look at the code available.

I see them often used to wrap some state, in IO or GUIs.
However they are not that much used for what they are often used in C++: 
program structuring.
(There are exceptions: ocamldoc uses lots of inheritance)
If you want just to structure your program, modules are better in most cases.
There are still situations where classes are stronger than modules for 
* when you have a default for some operation, but want to be able to change it
* when you want to mix components, using multiple inheritance and virtual 
  and instance variables

Also, for various reasons, objects are not beginner friendly.
I think the main problem is that they don't fit that well with type inference:
both subtyping and polymorphic methods require explicit type annotations.
This is worse than having long error messages: correct programs (at least 
programs that
would be correct in a really principal type system) get refused for reasons 
are hard to understand for  beginners.
For this reason and others, I think that both objects and polymorphic 
variants are mostly
useful in library design, where you give the user a protocol to use them.
This greatly reduces the risk of getting into trouble.

On the other hand, I don't think many features are missing from the point of 
view of expressivity.
As I mentioned in my previous mail, ocaml now has an override keyword, and it 
a hard error to override a non-defined method.
All warnings can be turned into errors, and when programming with objects it 
is a good
idea to activate the ones disabled by default.

Concerning friend methods, it is indeed possible to block access at the 
method level,
but I would rather suggest using private rows:

module Cell : sig
  type cell = private < get: int; give: cell -> unit; .. >
  val create : int -> cell
end = struct
  class cell x = object (_ : 'cell)
    val mutable x = x
    method get = x
    method set y = x <- y
    method give (c : 'cell) =
      x <- x - 1;
      c#set (c#get + 1)
  let create = new cell

You cannot inherit from cell, but I would believe this is not a problem in 
most situations.
I see nothing strange in privacy control being at the module level: protected
in Java is also at the package level rather than the class level. And it is 
not to duplicate functionality.

I won't really enter the discussion about information hiding.
Encapsulation is central to OO, but whether it is information hiding or not is
an open issue :-)

insert ocaml source in latex


Michel Lévy asked and Benoit Montagu replied:
> I want to insert some Ocaml expressions in latex, but by cut/paste it's
> impossible, because I lose
> the identation.
> Do you have a solution to insert Ocaml source in latex document ?
> Do you know if someone has written a definition for using ocaml with the
> listings package ?

It might not be up to date, but there is one that is included in the default listings package. 


should work.
Maxence Guesdon also suggested:
You may have a look at highlight:
Michel Lévy then said:
Thank you all, for your answers to my questions. 
But for my limited needs, I have also seen that cut/paste was a
solution, if, in emacs, you replace the tabs by spaces. For example,
M-x untabify replaces in a selected region the tabs by spaces.



Gerd Stolpmann announced:
A new version of Ocamlnet has been released: Version 3.4 mainly focuses
on smaller usability improvements:

- Ocamlnet has been ported to IPv6 (or better, this project is now
- The apache module understands now a NetcgiRequire directive which
  works in the same way as #require in the toploop.
- The methods read_file and write_file have been added to the
  Netfs.stream_fs abstraction for accessing filesystems. These
  methods allow it to avoid temporary files in some cases.
- Netplex prints now line numbers when emitting messages about
  errors in the config file.

Plus some smaller changes (see ChangeLog).

The project page with all relevant links (manual, download, etc):

GODI for Ocaml-3.12 is already updated.

Other Caml News

From the ocamlcore planet blog:
Thanks to Alp Mestan, we now include in the Caml Weekly News the links to the
recent posts from the ocamlcore planet blog at

JavaLib and Sawja Javalib 2.2.1 a:

Zarith 1.0:

data Maybe -- harmful?:

Opa advocacy:

Opa on Lambda the Ultimate (and now Slashdot):

Type fascism..:

ocaml random string and word generation:

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