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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 0617CBBAF for ; Tue, 4 May 2010 13:54:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4BAD6o30tQW+UMmWdsb2JhbACDF413jCMVAQEBAQEICwoHESKqDpEDgSaCf24EhjM X-IronPort-AV: E=Sophos;i="4.52,327,1270418400"; d="scan'208";a="58581590" Received: from lo.gmane.org ([80.91.229.12]) by mail1-smtp-roc.national.inria.fr with ESMTP; 04 May 2010 13:54:09 +0200 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1O9GhU-0003DZ-He for caml-list@inria.fr; Tue, 04 May 2010 13:54:08 +0200 Received: from ks368928.kimsufi.com ([94.23.39.26]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 04 May 2010 13:54:08 +0200 Received: from sylvain by ks368928.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 04 May 2010 13:54:08 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr connect(): No such file or directory From: Sylvain Le Gall Subject: Re: Subtyping structurally-equivalent records, or something like it? Date: Tue, 4 May 2010 11:53:58 +0000 (UTC) Message-ID: References: <602616.65342.qm@web111501.mail.gq1.yahoo.com> <4429.86797211251$1272970133@news.gmane.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ks368928.kimsufi.com User-Agent: slrn/pre1.0.0-11 (Linux) X-Spam: no; 0.00; le-gall:01 subtyping:01 lri:01 ocaml:01 compiler:01 variants:01 pointer:01 indirection:01 indirection:01 compiler:01 ocamlopt:01 wrote:01 constructor:01 constructor:01 variant:02 On 04-05-2010, AUGER Cédric wrote: > I am not expert in Ocaml, is the following the same in terms > of performances as the phantom types? > > type kinematic = ... > > type force = Force of kinematic > type momentum = Moment of kinematic > ... > > That is does the constructor introduce an overhead or not? > As there is only one constructor, no overhead should be done in an > optimized compiler. > The variants are represented using a block. If you introduce a single variant, it will create a block that points to kinematic. E.g. "Force of kinematic" will create a pointer to the kinematic structure. Your construction of force and momentum will add a level of indirection for every use of the kinematic structure. Phantom type doesn't add a level of indirection and left no trace in the generated assembler. This is not about optimized compiler in this case but about data representation. Even if you use an optimized compiler (which is not really the case with ocamlopt), you won't change datastructure representation to optimize. Regards, Sylvain Le Gall