From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B3B8DBC57 for ; Thu, 5 Aug 2010 17:02:16 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak0CABRvWkxDww/TkWdsb2JhbACDFZAHMIM2iUwBAQEBCQsKBxEDH7QPO4IQhhCJAgEEBAGBIYMhcwSEIA X-IronPort-AV: E=Sophos;i="4.55,322,1278280800"; d="scan'208";a="65076107" Received: from web111514.mail.gq1.yahoo.com ([67.195.15.211]) by mail1-smtp-roc.national.inria.fr with SMTP; 05 Aug 2010 17:02:15 +0200 Received: (qmail 18947 invoked by uid 60001); 5 Aug 2010 15:02:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1281020534; bh=0ySOwNlDPeohOdLOqBxEQVC1cYplsZcbBSCRL6LHHvg=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=hSR5Xyqw8PZyowm9+bo7uThw5JpLnWXhrvzclbwUe1A/HztSDU7HIZ6gWNRfFAHBS8yGt7Ela+x4XFD/GFJsklz+CWtcDTQct5EFBwYQresgPUACvFYd6uaSv/6Dr18RgP0eb2zFsfyrF9nSg43FosnbOIhWp7ZTbk+cD+tY0U8= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=f97Dt9SqavZqE8wrZR+SUSQltEvApYURavIafR4puCEBR0vGz/cR+sllo6PPPXNAGIqMGqKTMFRc+AncUgUVv9zbyDCuNK0nRe+xp+HuFX05sPRKbQtbJXJAI3YaUR2inGLjCoA5xvSG9ZS3qxWdhrJL4kKHnaNaVHb8Ua6rk2g=; Message-ID: <607998.18398.qm@web111514.mail.gq1.yahoo.com> X-YMail-OSG: 0C.2eAMVM1kicvNPb0Ev3QwdDe_2lnp8NwPlHI99X5O9s.R oNz0eXEin1WrmP.FQYTpDnf63dnAtSuqfyPJmWIm3N6Go5ib00wfpwAeVjT1 neA9lVoZLULRHXiF7IUd1ExZKkCV8vi6y1yHxDYlFFtdyn.2d3oVPJXUqZUe NMM2a96EAi6K76FUL.y8sN3KnZ4slU4ieXozWI0.KZd0Dxc7_8HKpWhhAoMc ZGUkIEpfOdwTl.SzN44M7FE1lNd5EGP_EcSwaRfzcA_r5oM9fmaj9_VM3bax hvtG8XgtxdNimyiJ529M_EFEe2m0e4J4_WRRcbhE6 Received: from [213.205.71.61] by web111514.mail.gq1.yahoo.com via HTTP; Thu, 05 Aug 2010 08:02:14 PDT X-Mailer: YahooMailClassic/11.3.2 YahooMailWebService/0.8.105.279950 Date: Thu, 5 Aug 2010 08:02:14 -0700 (PDT) From: Dario Teixeira Subject: Emulating width subtyping with 1st-class modules To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; subtyping:01 subtyping:01 ocaml's:01 sig:01 val:01 val:01 sig:01 printf:01 printf:01 struct:01 struct:01 verbose:01 camlp:01 short:01 int:01 Hi,=0A=0AI have a problem where some form of width subtyping for records wo= uld be=0Auseful. At the present I'm taking advantage of the structural sub= typing nature=0Aof Ocaml's object system to emulate the width subtyping. T= his works and is=0Areasonably compact, but I'm still open to other approach= es. It has occurred=0Ato me that 3.12's modules-as-first-class-values prov= ide yet another solution:=0A=0A=0Amodule type BRIEF =3D=0Asig=0A=09val a: i= nt=0A=09val b: string=0Aend=0A=0A=0Amodule type FULL =3D=0Asig=0A=09include= BRIEF=0A=09val c: float=0Aend=0A=0A=0Alet print_brief m =3D=0A=09let modul= e M =3D (val m: BRIEF) in=0A=09Printf.printf "A: %d, B: %s\n" M.a M.b=0A=0A= =0Alet print_full m =3D=0A=09let module M =3D (val m: FULL) in=0A=09Printf.= printf "A: %d, B: %s, C: %f\n" M.a M.b M.c=0A=0A=0Amodule Full =3D=0Astruct= =0A=09let a =3D 1=0A=09let b =3D "full"=0A=09let c =3D 0.5=0Aend=0A=0A=0Amo= dule Brief =3D=0Astruct=0A=09let a =3D 0=0A=09let b =3D "short"=0Aend=0A=0A= =0Alet () =3D=0A=09print_brief (module Brief : BRIEF);=0A=09print_brief (mo= dule Full : BRIEF);=0A=09print_full (module Full : FULL)=0A=0A=0AWhile this= approach seems awfully verbose, I reckon it could be made much=0Amore pala= table via some Camlp4 sugaring. Nevertheless, I have a question:=0Ajust ho= w heavy would this approach be when compared to the object one?=0AAnd how w= ould it fare in comparison to regular records?=0A=0AThanks for your attenti= on!=0ABest regards,=0ADario Teixeira=0A=0A=0A=0A