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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 8F619BBAF for ; Wed, 5 May 2010 13:10:41 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcBAF/v4EtKfVI0mGdsb2JhbACdOwgVAQEBAQEICQwHESKtVQqBdoUwLohOAQEDBYJVgjkEjHU X-IronPort-AV: E=Sophos;i="4.52,333,1270418400"; d="scan'208";a="50506667" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 May 2010 13:10:41 +0200 Received: by wwi14 with SMTP id 14so1641056wwi.39 for ; Wed, 05 May 2010 04:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:reply-to :in-reply-to:references:date:message-id:subject:from:to:cc :content-type; bh=ulIReUYBJp2BGEMJ2xIOUyN4WVMF9ZMZ7TpbSdEz34I=; b=JErtLqhTDtTCGO6OUWI/5OBqYkWXiCAujOcJSIVUZp9PmuBH3Sq4Uc4dgxjYKfUS/7 dOSdvaSa9JojFTmRbe8xQcj9HcYC0B1DXeVxkRmBipqIQ6yM/nuy8CbAWhp5iWenf/C8 9QsDSnKUmanaWV1nAuTcuB8zKO5VkHoWOJOFM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; b=FPzI0HhA01uCtw42HQL6uPYIE/lGJgtTQHNxgTGxPZIPd5lUzsIiWGowktsRe6UmC9 rA9QlUXTtqhYUOCdZttVqqPfSvWIRkjFRVbqImpJz7J1oKzEx9byMD9myh1ZZTwpk94J /z6E4c/wBeV0tFZsoUcEBR9q3PQ/zBDmDv5cY= MIME-Version: 1.0 Received: by 10.216.157.73 with SMTP id n51mr1865403wek.159.1273057840821; Wed, 05 May 2010 04:10:40 -0700 (PDT) Received: by 10.216.73.207 with HTTP; Wed, 5 May 2010 04:10:40 -0700 (PDT) Reply-To: yminsky@gmail.com In-Reply-To: <4BE02308.2080902@gmail.com> References: <602616.65342.qm@web111501.mail.gq1.yahoo.com> <4429.86797211251$1272970133@news.gmane.org> <4BE02308.2080902@gmail.com> Date: Wed, 5 May 2010 07:10:40 -0400 Message-ID: Subject: Re: [Caml-list] Re: Subtyping structurally-equivalent records, or something like it? From: Yaron Minsky To: Edgar Friendly Cc: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=0016e64b9a026177180485d6e04c X-Spam: no; 0.00; subtyping:01 yaron:01 minsky:01 yminsky:01 sig:01 val:01 val:01 struct:01 inlining:01 runtime:01 struct:01 sig:01 inlining:01 runtime:01 edgar:98 --0016e64b9a026177180485d6e04c Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 4, 2010 at 9:37 AM, Edgar Friendly 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 --0016e64b9a026177180485d6e04c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, May 4, 2010 at 9:37 AM, Edgar Friendly <thelema314@gmail.com> wrote= :
module M : sig
=A0 =A0 =A0 =A0type momentum
=A0 =A0 =A0 =A0val of_kin : kinematic -> momentum
=A0 =A0 =A0 =A0val to_kin : momentum -> kinematic
end =3D struct
=A0 =A0 =A0 =A0type momentum =3D kinematic
=A0 =A0 =A0 =A0let of_kin x =3D x
=A0 =A0 =A0 =A0let to_kin x =3D x
end

Yes, it's a lot of boilerplate for each type, but you only have to writ= e it once (per type), and cross-module inlining should give zero runtime co= st. =A0If not, use "%identity", and expose it in the interface. = =A0This method is along the lines of Anthony's proposal #4.

You can do the above solution with essentially no boilerplate:
=
module M =3D struct
=A0=A0 type t =3D kinematic
=A0=A0 val to_kin= x =3D x
=A0=A0 val of_kin x =3D x
end

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

module Momentum : S =3D M<= br>module Position : S =3D M
module Force : S =3D M

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

That s= aid, I still think the phantom type solution will end up cleaner.

y
--0016e64b9a026177180485d6e04c--