Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: tab@s...
Subject: Re: [Caml-list] Ocaml compiler features
On Wed, Jan 17, 2007 at 02:46:13PM +1100, skaller wrote:
> > 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.
> 
> 
> Of course any specific example has a work around:
> 
> 	let finally u f = try u () with e -> f (); raise e in
> 
> 	let u () = GlMat.push(); GlMat.mult m in
> 	let f () = GlMat.pop() in
> 	finally u f

Again, it would more convincing if the code you wrote was correct.
Here the f function doesn't get call if u didn't raise an exception.
We want the f function to be called in ALL case.

> This would, however, be a mess if the push/pop things were
> nested (which is likely I guess). Felix provides the syntax

This is not about Felix.

> which is very convenient for this idiom:
> 
> 	finally { push GlMat; mult GlMat m; } { pop GlMat; };

And I would wrote it in OCaml with the abstraction function I have:

	finally (fun () -> push GlMat; mult GlMat m) (fun () -> pop GlMat);

See, you can also show what you want to show without talking about
language X on language Y's ML, and thus been more on topic.

Cheers,
-- 
Vincent Hanquez