From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 35673BCAE for ; Fri, 8 Jul 2005 17:55:52 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j68FtpE3027824 for ; Fri, 8 Jul 2005 17:55:51 +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 RAA30846 for ; Fri, 8 Jul 2005 17:55:51 +0200 (MET DST) Received: from mail.physik.uni-muenchen.de (mail.physik.uni-muenchen.de [192.54.42.129]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j68Ftoxe027818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 8 Jul 2005 17:55:51 +0200 Received: from localhost (unknown [127.0.0.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 8128020018; Fri, 8 Jul 2005 17:55:50 +0200 (CEST) Received: from mail.physik.uni-muenchen.de ([127.0.0.1]) by localhost (mail.physik.uni-muenchen.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 17841-01-24; Fri, 8 Jul 2005 17:55:48 +0200 (CEST) Received: from mailhost.cip.physik.uni-muenchen.de (kaiser.cip.physik.uni-muenchen.de [141.84.136.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 9F9E520017; Fri, 8 Jul 2005 17:55:48 +0200 (CEST) Received: from katrin.cip.physik.uni-muenchen.de (katrin.cip.physik.uni-muenchen.de [141.84.136.12]) by mailhost.cip.physik.uni-muenchen.de (Postfix) with ESMTP id D51BC26E89; Fri, 8 Jul 2005 17:55:47 +0200 (CEST) Received: by katrin.cip.physik.uni-muenchen.de (Postfix, from userid 3092) id B9A8616BBA; Fri, 8 Jul 2005 17:55:38 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by katrin.cip.physik.uni-muenchen.de (Postfix) with ESMTP id B403D22135; Fri, 8 Jul 2005 17:55:38 +0200 (CEST) Date: Fri, 8 Jul 2005 17:55:38 +0200 (CEST) From: Thomas Fischbacher To: Olivier Andrieu Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to raise_with_arg() a tuple? In-Reply-To: <17101.30588.827486.654309@karryall.dnsalias.org> Message-ID: References: <17101.30588.827486.654309@karryall.dnsalias.org> X-BOFH: Daemons did it MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: amavisd-new at physik.uni-muenchen.de X-Miltered: at concorde with ID 42CEA207.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42CEA206.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 andrieu:01 exn:01 defines:01 exn:01 parens:01 foo:01 foo:01 syntax:01 ocaml:01 haskell:01 syntax:01 ocaml:01 haskell:01 wishlist:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Thu, 7 Jul 2005, Olivier Andrieu wrote: > > exception Test_exn of int * int > > It's the usual gotcha with variant constructor that have multiple > arguments. The exception you defines has two arguments, whereas > > exception Test_exn of (int * int) > > has only one argument -- a tuple. It's not the same thing. Oh dear. Indeed, if I just put parens around int * int, then everything is fine. I don't know how other readers on the list think about this, but somehow I consider this a pretty bad tripwire. After all, I would not have expected behaviour like this: # type foo = | Foo1 of int * int | Foo2 of (int * int) ;; type foo = Foo1 of int * int | Foo2 of (int * int) # Foo1 (2,3);; - : foo = Foo1 (2, 3) # Foo2 (2,3);; - : foo = Foo2 (2, 3) # let x = (2,3) in Foo1 x;; Characters 17-23: let x = (2,3) in Foo1 x;; ^^^^^^ The constructor Foo1 expects 2 argument(s), but is here applied to 1 argument(s) # let x = (2,3) in Foo2 x;; - : foo = Foo2 (2, 3) # Foo1 2 3;; Characters 7-8: Foo1 2 3;; ^ Syntax error While it is certainly nice that there is an OCaml equivalent (I presume) of what would be written in Haskell as: data Foo = Foo1 (Int,Int) | Foo2 Int Int deriving Show Main> :load /tmp/1.hs Main> Foo1 (2,3) Foo1 (2,3) Main> Foo2 2 3 Foo2 2 3 (I did not know about this so far!), the syntax used by ocaml certainly is quite misleading. As well, it seems to be a bit un-orthogonal here: after all, I cannot do this in OCaml (while it is allowed in Haskell, and might also be quite useful occasionally): # Foo1 2;; Characters 0-6: Foo1 2;; ^^^^^^ The constructor Foo1 expects 2 argument(s), but is here applied to 1 argument(s) Just as a further question, not to be meant as a suggestion or wishlist item: would it be conceivable that, at some point in the future, all the ocaml tools that operate on .ml files could accept different official "syntax variants" (say, the present one and a cleaned up syntax to be defined in the future), and dispatch between parsers via some command line argument or argv[0]? So that minor issues with the syntax could be repaired, should they turn out to be a problem. > actually it's ok to raise exception directly (ie, not through > CAMLreturn), the runtime takes care of releasing the local GC roots. Many thanks again for your explanation. -- regards, tf@cip.physik.uni-muenchen.de (o_ Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\ (lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_ (if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)