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 B2FF9BB81 for ; Fri, 24 Feb 2006 01:01:34 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k1O01WAS016351 for ; Fri, 24 Feb 2006 01:01:33 +0100 Received: from localhost (mikan [130.54.16.202]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id k1O01PVZ010632; Fri, 24 Feb 2006 09:01:25 +0900 (JST) Date: Fri, 24 Feb 2006 09:01:16 +0900 (JST) Message-Id: <20060224.090116.89069794.garrigue@math.nagoya-u.ac.jp> To: gava@univ-paris12.fr Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] (int * int) <> int*int ? From: Jacques Garrigue In-Reply-To: <00c201c638b1$b2b96860$1f570b50@mshome.net> References: <20060223185624.GA26907@old.davidb.org> <00bd01c638b0$9eeefda0$1f570b50@mshome.net> <00c201c638b1$b2b96860$1f570b50@mshome.net> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Miltered: at concorde with ID 43FE4CDC.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 gava:01 gava:01 structurally:01 syntax:01 datatypes:01 datatype:01 syntax:01 corrects:01 variants:01 12.:98 equality:01 polymorphic:01 polymorphic:01 pair: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.4 required=5.0 tests=DNS_FROM_RFC_ABUSE autolearn=disabled version=3.0.3 From: Fr=E9d=E9ric Gava > < For performance issues, is there a way to not have the rebuild > > of the pair in > > # type t =3D A of int*int | B of (int*int);; > > # fun x -> match x with A (a,b) -> (a,b) | B a -> a;; > > > > ? > Peraps this idea: > if (all the time) A of (int*int) =3D=3D> A of int*int then in pattern= mathching > "A a" the "a" is directly built as a tuple from the tuple of the conc= rete > type (just a little modification of the tag). Is it not a good idea ;= -) ? You can't do this, because values are shared: if you replace the A tag by 0, you have really changed the original value for x, and subsequent pattern-matching will be wrong. Interestingly, it would be safe to just return x itself: when you access a tuple you never look at its tag. However, this would still be incorrect because of polymorphic equality: A(a,b) is not structurally equal to 0(a,b) (assuming A is not the first tag.) So there's no solution here. By the way, the answer to your original question is that the syntax for datatypes is wrong. A datatype does not take a tuple as argument, but a fixed number of independent values. As somebody already pointed, the revised syntax corrects this. The standard syntax is just a consequence of history. This unfortunate syntax has consequences down to polymorphic variants, which otherwise could be represented more efficiently. Jacques