From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 01863BC37 for ; Fri, 29 May 2009 16:10:14 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsECAB+JH0pDww/BmWdsb2JhbACQSoEmhiUBAQEBAQgLCgcRpz+BE49PAQUDAYQIBQ X-IronPort-AV: E=Sophos;i="4.41,271,1241388000"; d="scan'208";a="40784890" Received: from web111511.mail.gq1.yahoo.com ([67.195.15.193]) by mail4-smtp-sop.national.inria.fr with SMTP; 29 May 2009 16:10:13 +0200 Received: (qmail 86079 invoked by uid 60001); 29 May 2009 14:10:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1243606212; bh=YZLX0wbHJXvhrs3xUxoJHXzaufX3LDnD7EZ9rgvHQUE=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=wHejKnbdDqKGNGJ90LZrnXf672ecPV1Ga1J8IUv1itfBsJ54yhy4LfC+sAR1J/lJ8AB9tJvUZA0dzfoeMm6YvaZBZGxv+do9SemDtpbsvxJoobErRsIWFNSDHgNUycrb4J93rJsU6tBKbwc6DuZXJyZjFptu5CWsJSayJZrWR1I= 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=Niec38/Yr+oCBtb+PlAURqcQRjC39l9tsi2XSSTUxBXopgA6r7HG3VqL9natLfrXD1Wvcbtwj/HVegjfApezFYUHCoPkUzOjOW2Cf2uUSfxrNtGnsgxxVaW4kjydhhTOqpQwbB0r0X6IWpKN37/MfHp3K9SprDQOtHfuAClAapk=; Message-ID: <327446.80988.qm@web111511.mail.gq1.yahoo.com> X-YMail-OSG: VdHJsjIVM1kIp5ucd3gBn0iv1R_luNDSpusDBrBMr1ySTlefYWYcAqxtgFmZRCb7qjAjzHV9sFnYZVrPipEXCBw1W2by3Jda96P6FLZjwsZFBGzMJQ9QLXJTlO4t89bM.jwmO.lNk6mOFUSVMuNoJNoDSU3N0isu95uihM_r.sykerbz.DY.tWH71LjQ0Eq9WCyxyo5mCCQIePTDbu3T5.wfuQUXKgq72ro2Gwahcisyio8Fl4QpIbCGH9ODpxPlQllyMh6OKrm5kbYeqDLaDyqdhVW0vPlcHEt9ZgW8A8gUD4ybFKb0hN59Xssmb6hoTT4wkA-- Received: from [213.205.71.63] by web111511.mail.gq1.yahoo.com via HTTP; Fri, 29 May 2009 07:10:12 PDT X-Mailer: YahooMailClassic/5.3.9 YahooMailWebService/0.7.289.10 Date: Fri, 29 May 2009 07:10:12 -0700 (PDT) From: Dario Teixeira Subject: Width subtyping 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 model:01 subtyping:01 ocaml:01 superset:01 constructors:01 subset:01 variants:01 polymorphic:01 int:01 int:01 width:97 width:97 declaring:02 types:05 Hi,=0A=0AThough it is probably been-there-done-that material for the vetera= ns in this list,=0Afor the sake of the not-so-veterans I have to ask: how d= o you guys typically model=0Awidth subtyping in Ocaml? Consider for examp= le three record types that share some=0Aof their fields:=0A=0Atype t1 =3D {= a: int; b: int; c: int; }=0Atype t2 =3D {a: int; b: int; c: int; d: = int;}=0Atype t3 =3D { b: int; c: int; d: int;}=0A=0AIn some circumst= ances, the object system can be put to good use for this kind of problem.= =0ANot always though, so I'm curious about other approaches people use. On= e approach=0AI've considered is to create a superset record where each fiel= d is an optional type,=0Aand then creating constructors/getters for each va= lid subset. Unfortunately this=0Asolution feels a bit kludgy, even if it r= educes code duplication. For safety reasons=0AI'm therefore currently just= declaring each record type independently (concerns about=0Aduplication be = damned).=0A=0AIn other words, polymorphic variants provide a very elegant s= olution for subtyping=0Awith sum types. Is there some brilliant idea that = could do the same for product types?=0A=0ABest regards,=0ADario Teixeira=0A= =0A=0A=0A=0A