From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 2E395BB84 for ; Sat, 17 Jun 2006 10:14:16 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k5H8EFVU004005 for ; Sat, 17 Jun 2006 10:14:15 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA20534 for ; Sat, 17 Jun 2006 10:14:14 +0200 (MET DST) Received: from selenite.metnet.navy.mil (selenite.metnet.navy.mil [192.16.167.32]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k5H8EBIo003993 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Sat, 17 Jun 2006 10:14:14 +0200 Received: (qmail 10238 invoked by uid 107); 17 Jun 2006 07:47:27 -0000 Received: from vwmetnet.metnet.navy.mil (192.16.167.21) by selenite.metnet.navy.mil with SMTP; 17 Jun 2006 07:47:27 -0000 Received: from Adric.metnet.fnmoc.navy.mil ([10.100.105.102]) by vwmetnet.metnet.navy.mil (NAVGW 2.5.2.9) with SMTP id M2006061707583801422 ; Sat, 17 Jun 2006 07:58:38 GMT Received: by Adric.metnet.fnmoc.navy.mil (Postfix, from userid 760) id 933DBAC97; Sat, 17 Jun 2006 00:45:52 -0700 (PDT) To: raffalli@univ-savoie.fr In-Reply-To: <4493239E.2050102@univ-savoie.fr> Cc: caml-list@inria.fr Subject: Re: [Caml-list] Resumable exceptions in plain OCaml Reply-To: oleg@pobox.com Errors-To: oleg@okmij.org From: oleg@pobox.com Message-Id: <20060617074552.933DBAC97@Adric.metnet.fnmoc.navy.mil> Date: Sat, 17 Jun 2006 00:45:52 -0700 (PDT) X-Miltered: at concorde with ID 4493B9D7.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4493B9D3.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 oleg:01 christophe:01 raffalli:01 foo:01 foo:01 ocaml:01 semantics:01 christophe:01 raffalli:01 camlp:01 camlp:01 syntax:01 polymorphic:01 polymorphic:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.0.3 Christophe Raffalli observed that > rraise (Foo i) (function Foo_r1 x -> ... | e -> raise e) "seems shorter, equivalent and more efficient" than > rraise (Foo i) (fun e -> try raise e with Foo_r1 x -> ...) that appeared in the posted code. I agree. In fact, to the best of my knowledge of the OCaml interpreter, the former is the semantics of the latter -- or, to be even more precise, the latter reduces to the former in the interpreter. The reason I chose the latter is: (i) to avoid writing the default clause "| e -> raise e", but mainly, (ii) to emphasize the similarity between pattern matching on the value (when invoking a function, for example) and pattern matching on the exception in the 'try' clause. The duality seemed irresistible to pass. > In fact exceptions in OCaml are one big polymorphic variant type that > existed before polymorphic variant where introduced ;-) So true. One of the motivations for the code resumable.ml was to (ab)use this fact. Christophe Raffalli also suggested > rraise Foo i with Foo_r1 x -> ... > is much clearer and certainly possible to define in camlp4 ? I agree again. I specifically wanted to avoid camlp4 in the original post, for the sake of naked details. Defining the right syntax, and implementing it with camlp4, was to be the next step.