Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Ocaml compiler features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-01-16 (19:43)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Ocaml compiler features
On Tuesday 16 January 2007 17:47, skaller wrote:
> In fact I have used Ocaml in a telco environment .. using
> the nice Event module, with many threads, services,
> and clients interacting in (soft) real time. That was some
> time ago so I can't say if I would have used 'finally'
> in that context or not. But typically I do that kind of
> thing the C way, which is generally the Ocaml way too:
> you propagate return codes from functions using variants
> up call chains.

Choosing boxing and unboxing over exceptions is fine if you have that choice 
and are willing to endure the performance degredation and added verbosity. 
However, you only have that choice if your code is self-contained. If you're 
writing a library where users can raise exceptions, you must be careful to 
undo state changes. In OpenGL, for example:

let transform m k x =
  GlMat.mult m;
    k x;
  with e ->
    raise e

could be rewritten:

let transform m k x =
  GlMat.mult m;
  try k x finally

Handling user-raised exceptions in this way is likely if you're using 
higher-order functions.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists