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=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 02A91BC69 for ; Tue, 26 Jun 2007 09:08:44 +0200 (CEST) Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5Q78hvJ025693 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Tue, 26 Jun 2007 09:08:43 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay05.plus.net with esmtp (Exim) id 1I35AI-0006co-SE for caml-list@yquem.inria.fr; Tue, 26 Jun 2007 08:08:43 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Execution time of class versus record Date: Tue, 26 Jun 2007 08:02:52 +0100 User-Agent: KMail/1.9.7 References: <467E8A6E.9050700@menta.net> <875c7e070706251715x61893212k62c9a15ce8e08989@mail.gmail.com> <6f9f8f4a0706252353g47af2ed6v8049476a71404add@mail.gmail.com> In-Reply-To: <6f9f8f4a0706252353g47af2ed6v8049476a71404add@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200706260802.52941.jon@ffconsultancy.com> X-Miltered: at discorde with ID 4680BB7B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; val:01 variants:01 trade-offs:01 non-trivial:01 ocaml:01 ocaml:01 frog:98 polymorphic:01 wrote:01 caml-list:01 constructor:01 constructor:01 pair:01 pair:01 int:01 On Tuesday 26 June 2007 07:53:01 Loup Vaillant wrote: > 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 Nope: # type t1 = A1 of int * int;; type t1 = A1 of int * int # type t2 = A2 of (int * int);; type t2 = A2 of (int * int) The former type has a contructor with two arguments. The latter type has a contructor with one argument that is a pair. Only in the latter case can you contruct directly from a pair: # let a = 1, 2;; val a : int * int = (1, 2) # A1 a;; The constructor A1 expects 2 argument(s), but is here applied to 1 argument(s) # A2 a;; - : t2 = A2 (1, 2) This distinction does not appear with polymorphic variants because they always adopt the latter representation. Despite the additional boxing, the performance trade-offs are non-trivial. For example, a pair can be extracted directly from the latter representation with no allocation required: # function A2 x -> x;; - : t2 -> int * int = whereas the former requires the construction of a pair: # function A1 x -> x;; The constructor A1 expects 2 argument(s), but is here applied to 1 argument(s) # function A1(x, y) -> x, y;; - : t1 -> int * int = -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. The OCaml Journal http://www.ffconsultancy.com/products/ocaml_journal/?e