Browse thread
Ocaml compiler features
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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.push();
GlMat.mult m;
try
k x;
GlMat.pop()
with e ->
GlMat.pop();
raise e
could be rewritten:
let transform m k x =
GlMat.push();
GlMat.mult m;
try k x finally
GlMat.pop()
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
http://www.ffconsultancy.com/products/ocaml_for_scientists