English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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-17 (14:09)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Ocaml compiler features
On Wed, 2007-01-17 at 12:41 +0100, Vincent Hanquez wrote:
> On Wed, Jan 17, 2007 at 02:28:47PM +1100, skaller wrote:
> > That is a reasonable argument to examine: but I'm not sure
> > finally is actually all that useful. If you're thinking of:
> > 
> > 	try maybe_throw X; do something
> > 	finally -> cleanup done
> > 
> > then it can be coded in Ocaml like:
> > 
> > 	begin try maybe_throw X; do something; cleanup
> > 	with x -> cleanup; throw x end
> It would be more convincing if you hadn't made the trivial mistake to
> put the first cleanup function in the try.
> if for a really weird reason cleanup raises an exception, cleanup is done twice.
> the correct OCaml code is:
> let r = try maybe_throw X; do something; with exn -> cleanup; raise exn in
> cleanup;
> r

My code lacks generality, in that it assumed the expression 
returned the unit. I see no difference whether the cleanup
is in the try or not: did I miss something?

[Well yes .. if the cleanup can raise an exception .. :]

> the point is not it's hard to do, it's annoything to duplicate here and
> there, and doing the inline code lose the higher level view we can have
> with a syntaxic sugar like try-finally.

I don't dispute these claims. However the same is true for many
features. We don't want to implement them all, so how do we choose?

The C++ committee basically chose features which either:

(a) were extremely common
(b) were so complex many people would get it wrong
(c) couldn't be done any other way

In addition, the C++ committee had limited time and couldn't
do everything. So a choice of a few features had to be made.

Some were accepted simply because they met the criteria and
were easy to implement, and others, although harder, provided
great benefit.

Given all these factors .. would you REALLY chose 'finally' as
a feature?

If I gave you just three features you could add .. would you 
REALLY waste one of your wishes on 'finally'?

> seems that you *finally* understand it ;)

Lol! I have no trouble understanding it. See above.
My issue is with whether it is really that useful and common
it really should be part of an already over rich language.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net