From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q1HIVmKY021884 for ; Fri, 17 Feb 2012 19:31:48 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlwCABacPk/UGyoBkWdsb2JhbABEgw+CBa0LIgEBAQEJCwsHFAMkgXYBBSMEUREJAiEWCwICCQMCAQIBRRMIAQGHfwame5IGjAMjNBCDKBsFARADCAMCAYI6gRYElTeFXY0M X-IronPort-AV: E=Sophos;i="4.73,439,1325458800"; d="scan'208,217";a="131860933" Received: from smtp1-g21.free.fr ([212.27.42.1]) by mail4-smtp-sop.national.inria.fr with ESMTP; 17 Feb 2012 19:31:44 +0100 Received: from [192.168.0.3] (bur91-2-82-231-161-160.fbx.proxad.net [82.231.161.160]) (Authenticated sender: tiphaine.turpin) by smtp1-g21.free.fr (Postfix) with ESMTPA id 8454394004D for ; Fri, 17 Feb 2012 19:31:37 +0100 (CET) Message-ID: <4F3EAB16.7060803@free.fr> Date: Fri, 17 Feb 2012 20:31:34 +0100 From: Tiphaine Turpin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111221 Thunderbird/8.0 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------050309090201060800040508" Subject: Re: [Caml-list] How an exception could be an argument This is a multi-part message in MIME format. --------------050309090201060800040508 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This behavior is expected given than OCaml is strict, and your operator <|||> would be an ordinary function (unlike || and &&). You have to use either functions (or lazy values) instead of expressions, or options instead of exceptions. Tiphaine Le 17/02/2012 19:16, Pierre-Alexandre Voye a écrit : > Hello, I'm trying to implement a scala concept "partial application" > in which one can chains pattern matching function. If the first > failed, the second is tried. > It seems it is impossible to give an exception as argument to a function. > > > > exception Nothing;; > > let (<|||>) a b = try a > with > > | Nothing -> (try b > with > > | Nothing -> raise > Nothing);; > > val ( <|||> ) : 'a -> 'a -> 'a = > > > (raise Nothing) <|||> > "jj";; > > Exception: Nothing. > > > But if I try : > try (raise Nothing) > with > > | Nothing -> (try > "jj"with > > | Nothing -> raise > Nothing);; > > - : string = "jj" > > Is there a workaround ? > > > Regards, > P-A > -- > --------------------- > https://twitter.com/#!/ontologiae/ > http://linuxfr.org/users/montaigne > --------------050309090201060800040508 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit This behavior is expected given than OCaml is strict, and your operator <|||> would be an ordinary function (unlike || and &&). You have to use either functions (or lazy values) instead of expressions, or options instead of exceptions.

Tiphaine


Le 17/02/2012 19:16, Pierre-Alexandre Voye a écrit :
Hello, I'm trying to implement a scala concept "partial application" in which one can chains pattern matching function. If the first failed, the second is tried.
It seems it is impossible to give an exception as argument to a function.



exception Nothing;;

let (<|||>) a b = try a with                                                                                                                                                                                                        
  | Nothing ->  (try b with                                                                                                                                                                                                           
                   | Nothing -> raise Nothing);;                                                                                                                                                                                      
val ( <|||> ) : 'a -> 'a -> 'a = <fun> 


(raise Nothing) <|||> "jj";;                                                                                                                                                                                                        
Exception: Nothing. 


But if I try :
try (raise Nothing)  with                                                                                                                                                                                                           
  | Nothing ->  (try "jj"with                                                                                                                                                                                                         
                   | Nothing -> raise Nothing);;                                                                                                                                                                                      
- : string = "jj" 

Is there a workaround ?


Regards,
P-A
--
---------------------
https://twitter.com/#!/ontologiae/
http://linuxfr.org/users/montaigne


--------------050309090201060800040508--