From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 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 20E3ABC69 for ; Tue, 26 Jun 2007 09:36:26 +0200 (CEST) Received: from orion.metastack.com (no-dns-yet.demon.co.uk [80.177.38.218] (may be forged)) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5Q7aPP2025035 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 26 Jun 2007 09:36:25 +0200 Received: from treble (cpc2-cmbg6-0-0-cust535.cmbg.cable.ntl.com [81.107.34.24]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id l5Q7TJCV029534 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Tue, 26 Jun 2007 08:29:20 +0100 From: "David Allsopp" To: References: <20070626065522.6175FBC77@yquem.inria.fr> Subject: Re: Execution time of class versus record Date: Tue, 26 Jun 2007 08:36:24 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <002701c7b7c4$b3083100$6a7ba8c0@treble> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 In-Reply-To: <20070626065522.6175FBC77@yquem.inria.fr> Thread-Index: Ace3vhGVlVWNTnHyQ4yZCe8gf7Zj2QAAkhbQ X-Miltered: at concorde with ID 4680C1F9.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; o'caml:01 foo:01 foo:01 variants:01 arises:01 notation:01 syntax:01 o'caml:01 26,:98 2007,:98 polymorphic:01 wrote:01 clearer:01 constructor:01 constructor:01 On Jun 26, 2007, at 08:53 AM, Loup Vaillant wrote: > > For the same reason, there is a difference between: > > > > type t = A of int * int > > > > and: > > > > type t = A of (int * int) > > Err, I don't get it : I see exactly the same thing (written twice) here. > > Are you telling that : > type t = A of int * int <==> type t = (A of int) * int > >? The type declarations are different - the top-level reports a different type in each case! The brackets matter because they tell O'Caml how many *arguments* the constructor A will take and so affect the internal representation. With the first type declaration, A(1, 2) is a 2-argument constructor and the value will be represented internally as a 2-field block with tag 0 with field 0 containing 1 and field 1 containing 2. This means that this code wouldn't work: let foo = (1, 2) in A foo but with the second type declaration it would. With the second type declaration, A (1, 2) is a 1-argument constructor and will be represented internally as a 1-field block with tag 0 with field 0 "pointing" to another 2-field block containing the 1 and 2. Section #18.3.4 of the manual explains the internal representation difference (esp. with ref to #18.3.6 where it is compared to Polymorphic Variants) but I was sure that there was an explicit reference in the manual to the difference between the type declarations but I can't find it now :( The confusion arises because the notation for arguments of a constructor and tuple construction look the same - I believe the "revised" syntax for O'Caml changes the way these are declared to make it clearer but I've never looked at it... David