From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 6D7677FD92 for ; Fri, 10 Jun 2016 20:34:32 +0200 (CEST) IronPort-PHdr: 9a23:gFyREhWU65mPMalLyos+w1YNFzDV8LGtZVwlr6E/grcLSJyIuqrYZhyDt8tkgFKBZ4jH8fUM07OQ6PCxHzNfqs/b6zgrS99laVwssY0uhQsuAcqIWwXQDcXBSGgEJvlET0Jv5HqhMEJYS47UblzWpWCuv3ZJQk2sfTR8Kum9IIPOlcP/j7n0oM2CJVoXz2PnOvtbF1afk0b4joEum4xsK6I8mFPig0BjXKBo/15uPk+ZhB3m5829r9ZJ+iVUvO89pYYbCf2pN4xxd7FTDSwnPmYp/4Wr8ECbFUrcrkcbB0UblBZSAguNxhb9W9+lsib8uvB82wGGOtXxTPYsXjO7qaxsTUm7pj0AMmsW/Xvbwvdsi6ZDpRunoVQrwojaZ6maOeByO7jBetcCQGNHWIBdWnoSUcuHc4ITAr9Zbq5jpI7nqg5L9EPmCA== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=info@gerd-stolpmann.de; spf=None smtp.mailfrom=info@gerd-stolpmann.de; spf=None smtp.helo=postmaster@mout.kundenserver.de Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=pra; client-ip=217.72.192.73; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=mailfrom; client-ip=217.72.192.73; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.kundenserver.de) identity=helo; client-ip=217.72.192.73; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="postmaster@mout.kundenserver.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CoAwBlB1tXfUnASNlehBR9szuHaoF6IoV1AoEqOhIBAQEBAQEBAREBAQkLCwkhL0ESAYFcghYBAQMBJy4kBQsLRlcGEwmIHwwBCa1Xb482AQEBAQEBBAEBAQEBFA6FL4VFhEyFTwWIBQeHFIQhhR6BNwKES4gkgjeHCQSFXI9rJQ2EEmwBhRuEbAEBAQ X-IPAS-Result: A0CoAwBlB1tXfUnASNlehBR9szuHaoF6IoV1AoEqOhIBAQEBAQEBAREBAQkLCwkhL0ESAYFcghYBAQMBJy4kBQsLRlcGEwmIHwwBCa1Xb482AQEBAQEBBAEBAQEBFA6FL4VFhEyFTwWIBQeHFIQhhR6BNwKES4gkgjeHCQSFXI9rJQ2EEmwBhRuEbAEBAQ X-IronPort-AV: E=Sophos;i="5.26,451,1459807200"; d="asc'?scan'208";a="221980517" Received: from mout.kundenserver.de ([217.72.192.73]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jun 2016 20:34:31 +0200 Received: from office1.lan.sumadev.de ([178.4.219.118]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0Lf0KF-1bnIdg3AuV-00qgEO; Fri, 10 Jun 2016 20:34:27 +0200 Received: from [192.168.5.133] (e130.fritz.box [192.168.5.133]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id 5489CDC05D; Fri, 10 Jun 2016 20:34:25 +0200 (CEST) Message-ID: <1465583657.32584.23.camel@e130.lan.sumadev.de> From: Gerd Stolpmann To: Hendrik Boom Cc: caml-list@inria.fr Date: Fri, 10 Jun 2016 20:34:17 +0200 In-Reply-To: <20160610181222.GA27973@topoi.pooq.com> References: <20160610181222.GA27973@topoi.pooq.com> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-aQHlaouHAsnYbENr9Zke" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 X-Provags-ID: V03:K0:UvCJLpIChQERLX+kRbTH3rM15ZooTMhXpaFEZikB7VwiPm4jALq ujwXEScvgWRcWFEXlnfSgwD1zFhAQC96Ea8W+2ZlETg2kprEyMGCKdQyXcrZmj9jb1SaeCA 9iCd6g6de4IkQAJkP8Gs+G/1K+obYK16KwONq0zHPkQMQfaELMb1AJ06NSdKZjgfso2OrE6 PdbMkAuU3BrjEGbj+hxkQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:i8fYKJbch8E=:94LV8i9TMQA3NRWTd6Z6cn 1tbsetiXfXqkL6uiFpfofAE//rJRBMMVkuRy4puvCflu0qnoZ4C4u+zHkDZwO7AS9oTfJBWrX MLEjWHxNA5ZoW1QEc5MStQAP3Mir4QgafFfcUCmSZxL8u0rNIWoggMktoy5VG2SSLOO8/2oa1 tlrWXeFFS5xZ5AN6+gP+N9EK93sFOd+sOl493CvImXBvLWgk/PnqO3CMAC6qGxyQ2glWi6BM9 DjjZ+KOBLINVgbqq+MtLj12J3zpPzPv7la8qZG++hKY5L3Li5qA5cLqH4CJUW0JEyD2ZcOx4x Zaq0iablhGcXp5nQIoXW9nErwm50Caq9B/Nrz0aXBj9ZKaHZnBBMafUdWhqgByROwsCbb3yUX U3cMjR0EidjAPeaLtGTnt5edmvm4Pv3j7gP0b50Awgsw3eD6mY7usIyEQm5TSXMgjzAMmYvs0 jFS36y6g+LIYN5KrBRKPc6qsYsU5h1vHhQhaR22trJcTi916dKoG7yO++JU47yEEM6KBaHH9Y CteMmGxN3YuEC29a2soIhi/5rhcSh6Xlaa+6n4eLTCYDzhfg4jcqVGkEIwtEgbP/jENRdAeAV BCFNJMQvj/YRu9tOi1esMe76GynCZutI0BGWpfN8+Zb8LakHbUd/kXOW4/UE56MppJlKmbgle r/HcQIGAD2wGYoGcPZhuKLlEr1iYZ+2Ja8H0aWr/0SvZML5PygMp75hHCnEbQgtVrDCI= Subject: Re: [Caml-list] reverse coercions --=-aQHlaouHAsnYbENr9Zke Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable Am Freitag, den 10.06.2016, 14:12 -0400 schrieb Hendrik Boom: > In http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-objects.html it says: >=20 > reverse coercions from a supertype to a supertype are never possible in=20 > OCaml. >=20 > (a) Might one of these 'supertype's actually be a 'subtype'? The second should be a subtype. > (b) Is there any way to do a run-time type-test on a value of a=20 > specific statically known supertype to test whether it is actually a=20 > value of a known specified subtype, and if so to proceed to use it as=20 > that subtype? This is not possible (essentially because subtyping is not bound back to the class hierarchy (a subclass is not necessarily a subtype), and there is no runtime representation of the types). To some extent you can emulate what you want with open variants, e.g. (untested): type leaftype =3D .. class type supertype =3D object ... method leaftype : leaftype end class type subtype =3D ... type leaftype +=3D | Subtype of subtype class subclass : subtype =3D object(self) inherit supertype method leaftype =3D Leaftype self ... end For every subclass, define a new variant for leaftype. Then, the test is let leafobj =3D match obj#leaftype with | Subtype x -> x | _ -> failwith "coercion failed" Gerd > If so, I'd like to use this in a site of pattern-directed rule=20 > invocations. >=20 > If not, I'd like to know if there are any well-known efficient ways=20 > around this. Of course I can effectively Godel-encode my data=20 > structures using lists, and interpret all my patterns and the=20 > application types I woyd have rather expressed as OCaml types, but I'm=20 > looking for something more elegant, statically checked, and=20 > efficient. >=20 > -- hendrik >=20 --=20 ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------ --=-aQHlaouHAsnYbENr9Zke Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEbBAABAgAGBQJXWwgpAAoJEAaM4b9ZLB5T6s4H93pEDDgeqKqjgW9r7podegKZ GY3JQpCR1KIBg//o0GHJGhNj15HrDXLr2rO4bt8YHRmEncBRMgw6x9z6QrabICfE 7kFsefHmxg3ZRWE7npDOAMS3AozjTp9aMnqZCqKzKDQ7nfKDcnOM+YaboM73Hv8Q SjyjNRnvs29KodSezFqx9xWhPRXSxoEIytaX24b1LKeI0EY2ReTBM7gp8pNvRBB1 LfYImBQPOZN3qN1OmL3v/I0eGOIn/4ozyRaWzdBsOSlJGmpcep7VG7dveLFe03ST 3o+fYf3qjs5Ifn7L2NWdkQGOJVVyH3NSxLESXcHDAZtmql9CX8GdGpvACIEFMQ== =glYQ -----END PGP SIGNATURE----- --=-aQHlaouHAsnYbENr9Zke--