caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Edgar Friendly <thelema314@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: Subtyping structurally-equivalent records, or something like it?
Date: Wed, 05 May 2010 11:33:50 +0200	[thread overview]
Message-ID: <871vdqbsld.fsf@frosties.localdomain> (raw)
In-Reply-To: <4BE02308.2080902@gmail.com> (Edgar Friendly's message of "Tue, 04 May 2010 09:37:12 -0400")

Edgar Friendly <thelema314@gmail.com> writes:

> On 05/04/2010 07:53 AM, Sylvain Le Gall wrote:
>> On 04-05-2010, AUGER Cédric<Cedric.Auger@lri.fr>  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


  reply	other threads:[~2010-05-05  9:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-01 19:55 [Caml-list] " Dario Teixeira
2010-05-01 20:01 ` Sylvain Le Gall
2010-05-04 10:33   ` [Caml-list] " AUGER Cédric
     [not found]   ` <4429.86797211251$1272970133@news.gmane.org>
2010-05-04 11:53     ` Sylvain Le Gall
2010-05-04 12:47       ` [Caml-list] " rossberg
2010-05-04 13:42         ` Sylvain Le Gall
2010-05-04 15:18           ` [Caml-list] " Fabrice Le Fessant
2010-05-05  9:31         ` Goswin von Brederlow
2010-05-05 12:12           ` rossberg
2010-05-05 16:46             ` Goswin von Brederlow
2010-05-04 13:37       ` Edgar Friendly
2010-05-05  9:33         ` Goswin von Brederlow [this message]
2010-05-05 11:10         ` Yaron Minsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871vdqbsld.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=thelema314@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).