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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id C6106BC5A for ; Wed, 5 May 2010 11:33:49 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArIBAKLY4EvZSMDjkWdsb2JhbACdQhUBAQEBCQsKBxEDH74GglqCOQQ X-IronPort-AV: E=Sophos;i="4.52,332,1270418400"; d="scan'208";a="49998528" Received: from fmmailgate02.web.de ([217.72.192.227]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 May 2010 11:33:48 +0200 Received: from smtp08.web.de ( [172.20.5.216]) by fmmailgate02.web.de (Postfix) with ESMTP id E77A915FC2F3B; Wed, 5 May 2010 11:33:47 +0200 (CEST) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1O9azD-000560-00; Wed, 05 May 2010 11:33:47 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.71) (envelope-from ) id 1O9azG-0005xy-5d; Wed, 05 May 2010 11:33:50 +0200 From: Goswin von Brederlow To: Edgar Friendly Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Subtyping structurally-equivalent records, or something like it? References: <602616.65342.qm@web111501.mail.gq1.yahoo.com> <4429.86797211251$1272970133@news.gmane.org> <4BE02308.2080902@gmail.com> Date: Wed, 05 May 2010 11:33:50 +0200 In-Reply-To: <4BE02308.2080902@gmail.com> (Edgar Friendly's message of "Tue, 04 May 2010 09:37:12 -0400") Message-ID: <871vdqbsld.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1/lW1aulKhHnotqkTG0EZwMQu363QnooMl+P+Ff 9fDM5RxFnQkU6SxXfJgrrm4BponV6i28bECSZl2kgDFzbosMqZ OrIcf/Jrs= X-Spam: no; 0.00; subtyping:01 lri:01 compiler:01 compiler:01 ocamlopt:01 ocaml:01 syntax:01 subtyping:01 sig:01 val:01 val:01 struct:01 struct:01 inlining:01 runtime:01 Edgar Friendly writes: > On 05/04/2010 07:53 AM, Sylvain Le Gall wrote: >> On 04-05-2010, AUGER Cédric wrote: >>> 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. >>> >> 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. >> > The OCaml compiler *could* special-case this kind of constructor, but > as there's the syntax: > > type momentum = kinematic > > Which produces the non-boxed kinematic values, the authors probably > decided to follow the maxim "Do what the programmer says" for > singleton variant types. The question becomes whether phantom types > solve this problem sufficiently or do we need another type-level > construct - > explicit subtyping relationships. Forever ago I suggested this to > achieve a similar goal, and was given yet another solution: > > module M : sig > type momentum > val of_kin : kinematic -> momentum > val to_kin : momentum -> kinematic > end = struct > type momentum = kinematic > let of_kin x = x > let to_kin x = x > end I think that can be cut down to: module M = struct type momentum = private kinematic let of_kin = %identity let to_kin = %identity end > Yes, it's a lot of boilerplate for each type, but you only have to > write it once (per type), and cross-module inlining should give zero > runtime cost. If not, use "%identity", and expose it in the > interface. This method is along the lines of Anthony's proposal #4. > > E. MfG Goswin