From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q1HIo7mq022463 for ; Fri, 17 Feb 2012 19:50:07 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsABAPagPk/RVaC2kGdsb2JhbABEFoR+rQMIIgEBAQEJCQ0HFAQjgXUBAQEEEgIPBBEIARscAgMMBgULDQICBRYLAgIJAwIBAgEREQEFARwTCAEBHodnm08KiyZMgnKFDD+IcwIFC4EkikkDBAMHBBEGCwICBQMFAwUDBAICAwIYA4NQAwgDDieCCIEWBIhOjGmHF4cSPYQg X-IronPort-AV: E=Sophos;i="4.73,439,1325458800"; d="scan'208";a="144806403" Received: from mail-gy0-f182.google.com ([209.85.160.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Feb 2012 19:50:01 +0100 Received: by ghbg15 with SMTP id g15so2811037ghb.27 for ; Fri, 17 Feb 2012 10:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=Pp52RdcJUfLlDpyaHSB0qVvU/nA9t3bbjZBEixV3RLQ=; b=Mv70DmeNxZVGbO/ykv3vUyO+v6ra3bj5XAkomA8+w8DAVJHtRr/+tbV+09ECdpUKcw NRyx6zZH0/28MMQ1pBMSiNAIaNwlAfMTBuZGm/y2aUUm1HN64I02SvRAqoWxt7B3tjVQ QqTS9NyyuQteYngKUsFixfzF6TBQWIxmHNXbA= Received: by 10.50.222.132 with SMTP id qm4mr25157612igc.21.1329504600393; Fri, 17 Feb 2012 10:50:00 -0800 (PST) Received: from page.encs.concordia.ca (page.encs.concordia.ca. [132.205.221.212]) by mx.google.com with ESMTPS id ch2sm12227996igb.4.2012.02.17.10.49.59 (version=SSLv3 cipher=OTHER); Fri, 17 Feb 2012 10:49:59 -0800 (PST) Message-ID: <4F3EA156.8010709@gmail.com> Date: Fri, 17 Feb 2012 13:49:58 -0500 From: Vincent Aravantinos User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.26) Gecko/20120201 Red Hat/3.1.18-1.el6_2 Thunderbird/3.1.18 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] How an exception could be an argument The arguments are evaluated before being passed to the function. So in your first test, "Nothing" is raised before even entering "<|||>". In the second case you're circumventing this by copying directly "raise Nothing" in the body of the function: this copy-pasting is not equivalent since you now force the evaluation of "raise Nothing" to happen within the scope of "try". * The following could be a workaround: # let (<|||>) (f1,arg1) (f2,arg2) = try f1 arg1 with Nothing -> try f2 arg2 with Nothing -> raise Nothing;; val ( <|||> ) : ('a -> 'b) * 'a -> ('c -> 'b) * 'c -> 'b = # ((fun _ -> raise Nothing),()) <|||> ((fun _ -> "jj"),());; - : string = "jj" It looks a bit heavy on this example because we are working with constants. But generally the constants come from some function application so it can fit in a not-so-ugly way in real code. * If you don't care about the infix, the following induces less parentheses: # let try_or_try f1 arg1 f2 arg2 = try f1 arg1 with Nothing -> try f2 arg2 with Nothing -> raise Nothing;; val try_or_try : ('a -> 'b) * 'a -> ('c -> 'b) * 'c -> 'b = # try_or_try (fun _ -> raise Nothing) () (fun _ -> "jj") ();; - : string = "jj" * Note that you can simplify the second try since "try blah with Nothing -> raise Nothing" is actually equivalent to "blah" This yields: # let (<|||>) (f1,arg1) (f2,arg2) = try f1 arg1 with Nothing -> f2 arg2;; val ( <|||> ) : ('a -> 'b) * 'a -> ('c -> 'b) * 'c -> 'b = On 02/17/2012 01:16 PM, Pierre-Alexandre Voye wrote: > (raise Nothing) <|||> "jj";; > Exception: Nothing. > > But if I try : > try (raise Nothing) with > | Nothing -> (try "jj"with > | Nothing -> raise Nothing);; > - : string = "jj" -- Vincent Aravantinos Postdoctoral Fellow, Concordia University, Hardware Verification Group http://users.encs.concordia.ca/~vincent