[
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: | 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 instance. Jacques Garrigue