From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id FAA10366; Sun, 24 Oct 2004 05:00:28 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA11096 for ; Sun, 24 Oct 2004 05:00:26 +0200 (MET DST) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.204]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9O30PCI017579 for ; Sun, 24 Oct 2004 05:00:26 +0200 Received: by rproxy.gmail.com with SMTP id 79so255025rnk for ; Sat, 23 Oct 2004 20:00:25 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=XeALMrx9dEHMaF5BtRnnKVJUFCzKFwNl0ap8U5GKlx1WQpd0IAN4XnVvapom8q4H+YY6D9HzgloAP1uS8WNC5sgde1Z+Hbz7nna8qQWOaTwIluRglgW0s2rVYbWuujMWrGomWYYTFat9g0j/uoug2d02N5AxuEnZKKWXG5dk8UM= Received: by 10.38.15.13 with SMTP id 13mr462910rno; Sat, 23 Oct 2004 20:00:25 -0700 (PDT) Received: by 10.38.14.54 with HTTP; Sat, 23 Oct 2004 20:00:25 -0700 (PDT) Message-ID: Date: Sat, 23 Oct 2004 23:00:25 -0400 From: John Prevost Reply-To: John Prevost To: caml-list@inria.fr Subject: Re: [Caml-list] Single-case union types as strong typedefs In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <20041023.123139.106410806.garrigue@kurims.kyoto-u.ac.jp> X-Miltered: at nez-perce with ID 417B1AC9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; prevost:01 prevost:01 caml-list:01 typedefs:01 2004:99 2004:99 jacques:01 boxing:01 1,3:01 1,3:01 n-tuples:01 foo:01 foo:01 baz:01 baz:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 23 Oct 2004 14:24:28 -0700, Nathaniel Gray wrote: > On Sat, 23 Oct 2004 12:31:39 +0900 (JST), Jacques Garrigue > wrote: > > With your example, there is no extra boxing involved. > > I.e. (1,3) and Rpos(1,3) and Apos(1,3) all share the same physical > > representation (a block with 2 fields). > > The problem you describe only occurs when your single constructor has > > only one argument. > > Really?? You're kidding. That's kind of cool but kind of strange -- > why does it only optimize for composite types? It's not so much that it's only optimized for "composite types" as that all of these constructors are *already* considered n-tuples. Think of it this way: type foo = Foo | Bar of int * int | Baz of int This is represented as something like: Foo = 0 Bar (x, y) = (0, x, y) Baz (x) = (1, x) (a, b) = (a, b) This isn't really what's going on, of course. (More precisely, which constructor was used is encoded in the block header.) But, it does provide enough of a model to see why what Jacques says is true. Essentially, you need to think of the tag as another integral piece of information. And then realize that everything bigger than an integer is (at least sometimes) boxed. So all of the above with (...) needs to be boxed. The true picture of the world is that there's a header at the start of the values in memory, and that header includes information about the length and which constructor was used. So the above in reality go to something more like: Foo = 0 Bar (x, y) = <0; 2; x; y> Baz x = <1; 1; x> (a, b) = <0; 2; a; b> (where represents a tagged block allocated by the Caml runtime, with tag t and length l, which is typically passed around as a pointer to v_0. See section 18.2.2 of the O'Caml manual for more detail.) So the first non-constant constructor for an algebraic type is represented the exact same way as a normal tuple. Any further constructors are identical except for the tag. John. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners