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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 0EE6FBC0B for ; Fri, 29 Dec 2006 07:05:37 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBT65YbS007529 for ; Fri, 29 Dec 2006 07:05:36 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id kBT65KvS026974; Fri, 29 Dec 2006 15:05:20 +0900 (JST) Date: Fri, 29 Dec 2006 15:05:07 +0900 (JST) Message-Id: <20061229.150507.32045202.garrigue@math.nagoya-u.ac.jp> To: skaller@users.sourceforge.net Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question on writing efficient Ocaml. From: Jacques Garrigue In-Reply-To: <1167326001.5338.0.camel@rosella.wigram> References: <200612281626.38328.jon@ffconsultancy.com> <1167326001.5338.0.camel@rosella.wigram> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 4594B02E.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 verbose:01 ocaml:01 optimise:01 sourceforge:01 wrote:01 constructor:01 constructor:01 caml-list:01 explicitly:01 pair:01 pair:01 int:01 int:01 argument:02 From: skaller > On Thu, 2006-12-28 at 16:26 +0000, Jon Harrop wrote: > > > The code is also needlessly verbose and inefficient. There's no point in > > declaring sum types with one contructor: > > > > type posn = Posn of int * int;; > > Doesn't Ocaml optimise the constructor away in this case? It's not really an optimization, rather that Posn being a constructor with 2 arguments (rather than a constructor taking a pair as argument), it ends up having exactly the same representation as a pair. So there is no loss in efficiency here. In general, I wouldn't explicitly advise against using single constructor type definitions for documentation, except when the argument is a single int or float and performance matters. Jacques Garrigue