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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 B3321BC37 for ; Sat, 30 May 2009 17:36:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwNALfvIEpDww+RdWdsb2JhbACQTIEmhiUBDAoLBxGmL4EUj1MBBQMBhAgF X-IronPort-AV: E=Sophos;i="4.41,276,1241388000"; d="scan'208";a="40825761" Received: from web111503.mail.gq1.yahoo.com ([67.195.15.145]) by mail4-smtp-sop.national.inria.fr with SMTP; 30 May 2009 17:36:28 +0200 Received: (qmail 49533 invoked by uid 60001); 30 May 2009 15:36:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1243697787; bh=8bdX3318OXraJzBBLZ7X6KGLlMPL3ygeaQC2ISJW94E=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ObmVf6IwrILwYAauM5v/6S75ew4MDRUiLRrtEvLFRCEEyZCTZ2tgpn5pn6L0aiAM/U4WIykZ4J3QDXETnsKzVrCP3+CD+HkaQwdfKc+rPj9wemmeFHrXnsbOBR0G928nvP0oluz22bdBN4nFxv4WI49EMcT+jtpRquM4Ruy+4QE= 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:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding; b=m8XYqeYJrER5tfcRaHscSvAqairz7FEXhncZiP0Nl7Y1zjEwEeF+1w2QT4qLbed5QLbnLVbdqrVs5fzYPv/QVDFJ5oRkQxK9Cu2fiHNmG3LUy0i1GvS0HmIus/f4w7l4DxGnNnqCqiGnc88PdNt3DlNOVpQ2OdvYa8xTvylWNSk=; Message-ID: <380372.47429.qm@web111503.mail.gq1.yahoo.com> X-YMail-OSG: aIlK4UsVM1lEbCqbDsLvN6Bf0be5GWBRCbvSH_hNGgGUU5dqWUsh1LVN.YGKfbxa4q9wzHzljigZCBOvSNf1zvCQSZYiN_SOgHbbBgAKQvLrUP5Xwd_dKyuKUfWg6qXfNvwBzn.vumaoY0Zq83VB6kisbdwqdjolYsAoiklZ5CUt7CMeXY.S.finUTAQAW._czpXhDPq7_mSES4Y2Tuvk5sfnSl4sZgsrVVgVf6Q.4STjIGoNhNmMf5fGYqwKhSSrs_wwymE20Z_gLTvfd1YGc3ipWTc0WyYvwXF9tMskui53Ujy6ps76r0- Received: from [213.205.71.58] by web111503.mail.gq1.yahoo.com via HTTP; Sat, 30 May 2009 08:36:27 PDT X-Mailer: YahooMailClassic/5.3.9 YahooMailWebService/0.7.289.10 Date: Sat, 30 May 2009 08:36:27 -0700 (PDT) From: Dario Teixeira Subject: Re: [Caml-list] Width subtyping To: Till Varoquaux Cc: 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 escapes:01 ocaml:01 translating:01 compile-time:01 runtime:01 runtime:01 fairness:01 printf:01 printf:01 foo:01 foobar:01 cheers:01 typing:01 caml-list:01 Hi,=0A=0A> There must be something that escapes me.... This seems to be an= =0A> example where ocaml objects really shine because of the structural=0A>= typing (i.e. an object is defined by the its structure):=0A=0AYou are righ= t. I was probably too fixated on the OOP way of doing this,=0Atranslating = record fields into object fields and the functions acting on=0Arecords into= object methods. Your solution, where record fields become object=0Amethod= s and external functions act on objects that match a certain structure,=0Ad= oes solve the inconveniences I mentioned before. But objects are still=0Aa= somewhat heavier solution, right?=0A=0AIn the meantime I also investigated= Polymap, and it is close to being the=0Aideal solution. It has one huge d= rawback, though: type inconsistencies=0Acannot be detected at compile-time,= producing instead runtime exceptions.=0AThe example below illustrates this= ; note that function printx should accept=0Aboth m1 and m2, but not m3. Ho= wever, the mistake in 'foobar' is not reported=0Auntil runtime: (In fairne= ss, there's probably no easy technical fix for this.)=0A=0Alet printx m =3D= Printf.printf "X is %d and Y is %s\n" m.`x m.`y=0A=0Alet m1 =3D `{x=3D1; y= =3D"foo"}=0Alet m2 =3D `{x=3D2; y=3D"bar"; z=3Dtrue}=0Alet m3 =3D `{y=3D"ol= a"; z=3Dfalse}=0A=0Alet foobar =3D=0A printx m1;=0A printx m2= ;=0A printx m3=0A=0ACheers,=0ADario=0A=0A=0A=0A