caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@math.nagoya-u.ac.jp>
To: yaoconglun@gmail.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] How to handle try .... finally properly?
Date: Thu, 11 Dec 2008 09:09:34 +0900 (JST)	[thread overview]
Message-ID: <20081211.090934.68540743.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <f7b50d2a0812100315m6c153153y59afc86e02ae8a1e@mail.gmail.com>

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


  parent reply	other threads:[~2008-12-11  0:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-10 11:15 Conglun Yao
2008-12-10 22:58 ` [Caml-list] " blue storm
2008-12-11  0:09 ` Jacques GARRIGUE [this message]
2008-12-11  0:52   ` Conglun Yao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081211.090934.68540743.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=yaoconglun@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).