From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id D3579BB84 for ; Thu, 11 Dec 2008 01:09:38 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEACfpP0mFBoIF/2dsb2JhbADGDwEE X-IronPort-AV: E=Sophos;i="4.33,749,1220220000"; d="scan'208";a="21093572" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail1-smtp-roc.national.inria.fr with ESMTP; 11 Dec 2008 01:09:37 +0100 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 0827DB661; Thu, 11 Dec 2008 09:09:35 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id B915688B1; Thu, 11 Dec 2008 09:09:34 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=alpha; bh=bl8jGPsYPVBsB4TQPNHAuxcR2nU=; b=jPIE22nDv2ea5Br8lz8GFV4S4ZSN jSgItcW4dITyt9QTemxmHqFjCqfM2OBM8gKRzgGdnJJuDYF09hW5nxiPNf3iwDLb Mp27FOhN0urKxTsjryuo/smsZAiHHZqGvht4GtE04WHbZCsw3Y/F0xVDYqvibkV9 1V0IQvyNUwds3ng= DomainKey-Signature: a=rsa-sha1; h=Received:Date:Message-Id:To:Cc:Subject:From:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding; b=Ay5DdRw0Suq0Qahh0s1b1rQwHsNGDgjftDPhQCe6zseHGrHIEjR1HExFRyoFA6BJ4d3ST+XYaHp9znbsAX7E+QiSIfFDGovHGlqZG8Wznflh2yznNYp1Bt3BiDQblCAbGi4Id7m9euRFFBxwRiVHZJlkhUqcs1i8dVDUElnCcBk=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from localhost (rabbit-172 [172.16.254.254]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 8D70A88AE; Thu, 11 Dec 2008 09:09:34 +0900 (JST) Date: Thu, 11 Dec 2008 09:09:34 +0900 (JST) Message-Id: <20081211.090934.68540743.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? From: Jacques GARRIGUE In-Reply-To: References: X-Mailer: Mew version 4.2 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; printf:01 .....:98 invoke:01 partial:01 caml-list:01 functions:01 partially:02 partially:02 argument:02 argument:02 garrigue:03 garrigue:03 workaround:03 jacques:03 jacques:03 From: "Conglun Yao" > 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