caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@gmail.com>
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, 5 May 2010 07:10:40 -0400	[thread overview]
Message-ID: <q2i891bd3391005050410kd085968fh5ad34d9413fab96f@mail.gmail.com> (raw)
In-Reply-To: <4BE02308.2080902@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]

On Tue, May 4, 2010 at 9:37 AM, Edgar Friendly <thelema314@gmail.com> wrote:

> 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
>
> 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.


You can do the above solution with essentially no boilerplate:

module M = struct
   type t = kinematic
   val to_kin x = x
   val of_kin x = x
end

module type S = sig
  type t
  val to_kin : t -> kinematic
  val of_kin : kinematic -> t
end

module Momentum : S = M
module Position : S = M
module Force : S = M

and so on.  Just  one line per kinematic-like type you want to create.

That said, I still think the phantom type solution will end up cleaner.

y

[-- Attachment #2: Type: text/html, Size: 1479 bytes --]

      parent reply	other threads:[~2010-05-05 11:10 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
2010-05-05 11:10         ` Yaron Minsky [this message]

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=q2i891bd3391005050410kd085968fh5ad34d9413fab96f@mail.gmail.com \
    --to=yminsky@gmail.com \
    --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).