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
How to handle try .... finally properly?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-12-11 (00:09)
From: Jacques GARRIGUE <garrigue@m...>
Subject: Re: [Caml-list] How to handle try .... finally properly?
From: "Conglun Yao" <yaoconglun@gmail.com>
>    Example Input :
>      let transform f x =
>        GlMat.push();
>        try f x
>        finally GlMat.pop()
> At the first glance, it answered my question. However, it solved the
> problem partially, only working on functions with one argument.
> If we feed the * transform * a function with more than one argument,
> (it is possible because of curring)
> transform (fun x y -> .... some logic staff .... ) x y
> will invoke the * after () * before the ((fun x y -> .....) x) y is
> really executed.

A usual workaround in such situations is to first partially apply your
function to the (n-1) first arguments, as this should cause no
side-effects. Since I suppose you are really talking about

  transform f x y

you should rather write

  transform (f x) y

Note that this will not work properly if partial applications of f cause
side-effects (i.e. f is actually "fun x -> ...; fun y -> ...").
This is pretty rare, but I believe this is the case for printf for

Jacques Garrigue