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 2000A7F616 for ; Wed, 22 Feb 2017 20:04:19 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mandrykin@ispras.ru; spf=Pass smtp.mailfrom=mandrykin@ispras.ru; spf=None smtp.helo=postmaster@smtp.ispras.ru Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of mandrykin@ispras.ru) identity=pra; client-ip=83.149.199.196; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mandrykin@ispras.ru"; x-sender="mandrykin@ispras.ru"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of mandrykin@ispras.ru designates 83.149.199.196 as permitted sender) identity=mailfrom; client-ip=83.149.199.196; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mandrykin@ispras.ru"; x-sender="mandrykin@ispras.ru"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.ispras.ru) identity=helo; client-ip=83.149.199.196; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mandrykin@ispras.ru"; x-sender="postmaster@smtp.ispras.ru"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AjLQ8GhUMDffriRlovmO04TnpqSXV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZhGHt8tkgFKBZ4jH8fUM07OQ6PG9HzVeqs/Y4ThCKMUKDEBVz5?= =?us-ascii?q?1O3kQJO42sNw7SFLbSdSs0HcBPBhdO3kqQFgxrIvv4fEDYuXao7DQfSV3VPAtx?= =?us-ascii?q?IfnpSMaJ15zkn8j7wZDYYh1JiTyhevsyaUzu9USCgPILmpNvIbodzR7Ao30AO7?= =?us-ascii?q?gHhDAgGVXGlB/54oK0/YV/2yVWofMoscBaFe3bYa0+BZNfEDM4OGA0+Naj4Rjd?= =?us-ascii?q?QiOO63YRFGIMnUwbLRLC6UTfX5Txuyr+/s903iWALM73S/hgXD2k4716Sx7uoC?= =?us-ascii?q?YcLyQw6yfNl5oj3+pgvBu9qkknkMbva4aPOa87I/rQ?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0D3BQDN361Y/8THlVNeGwEBAQMBAQEJA?= =?us-ascii?q?QEBFQEBAQECAQEBAQgBAQEBhAeBCYNbinqQaII6ihSKcyqDDoJqAoNJFQEBAQE?= =?us-ascii?q?BAQEBAQEBYSiCMwQBHQWCFwEFIwRHCxAJAhgCAgUEHQICDwE1EgYBEhKJSwMZC?= =?us-ascii?q?pFSnViBbDqHPQODdAEBAQcBAQEBASOBC4owhDAkgwaCXwWHOAyICHuLSYZ0jX2?= =?us-ascii?q?HaIZakyU1IoEANS5Ehkw9NYdXboFPAQEB?= X-IPAS-Result: =?us-ascii?q?A0D3BQDN361Y/8THlVNeGwEBAQMBAQEJAQEBFQEBAQECAQE?= =?us-ascii?q?BAQgBAQEBhAeBCYNbinqQaII6ihSKcyqDDoJqAoNJFQEBAQEBAQEBAQEBYSiCM?= =?us-ascii?q?wQBHQWCFwEFIwRHCxAJAhgCAgUEHQICDwE1EgYBEhKJSwMZCpFSnViBbDqHPQO?= =?us-ascii?q?DdAEBAQcBAQEBASOBC4owhDAkgwaCXwWHOAyICHuLSYZ0jX2HaIZakyU1IoEAN?= =?us-ascii?q?S5Ehkw9NYdXboFPAQEB?= X-IronPort-AV: E=Sophos;i="5.35,195,1484002800"; d="scan'208";a="261695485" Received: from bran.ispras.ru (HELO smtp.ispras.ru) ([83.149.199.196]) by mail2-smtp-roc.national.inria.fr with ESMTP; 22 Feb 2017 20:04:18 +0100 Received: from molnar.localnet (molnar.intra.ispras.ru [10.10.2.183]) by smtp.ispras.ru (Postfix) with ESMTP id 7505761283; Wed, 22 Feb 2017 22:04:16 +0300 (MSK) From: Mikhail Mandrykin To: caml-list@inria.fr, Ivan Gotovchits Cc: "Richard W.M. Jones" , Damien Guichard Date: Wed, 22 Feb 2017 22:04:16 +0300 Message-ID: <2432820.aHjfWRbG44@molnar> User-Agent: KMail/5.1.3 (Linux/4.4.0-62-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <20170222170101.GE28111@annexia.org> <20170222173814.GG28111@annexia.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Subject: Re: [Caml-list] List of structurally typed objects On =D1=81=D1=80=D0=B5=D0=B4=D0=B0, 22 =D1=84=D0=B5=D0=B2=D1=80=D0=B0=D0=BB= =D1=8F 2017 =D0=B3. 13:08:23 MSK Ivan Gotovchits wrote: > It is possible to generalize this approach using private row types. If at least a limited support for dynamic object typing is needed, it's als= o=20 possible to construct a heterogeneous container of objects using several=20 advanced features like first-class modules and GADT, but even in this case = the=20 exact type of the object should match precisely when extracted from the lis= t=20 or at least a finite (and small) number of possibilities for that type shou= ld=20 be known. It's, however, still possible to upcast the object to some supert= ype=20 upon addition and later extract and use it as the object of that supertype.= An=20 example: https://github.com/schrodibear/ocaml_tricks/blob/master/object_hli= st/ obj_list.ml Mikhail >=20 > list_fns.mli: >=20 > module Registry(Obj : sig > type t =3D private < .. > > end) : sig > val register_obj : string -> Obj.t -> unit > val get_obj : string -> Obj.t > end >=20 >=20 > list_fns.ml: >=20 > module Registry(Obj : sig > type t =3D private < .. > > end) =3D struct >=20 > let objs =3D ref [] > let register_obj name obj =3D objs :=3D (name, obj) :: !objs > let get_obj name =3D List.assoc name !objs > end >=20 >=20 > test.ml: >=20 > class foo =3D object > method hello =3D "hello from foo" > method goodbye () =3D print_endline "goodbye" > end >=20 > class bar =3D object > method hello =3D "hello from bar" > end >=20 > module Bars =3D List_fns.Registry(struct type t =3D bar end) >=20 > let () =3D > let o1 =3D new foo in > let o2 =3D new bar in > Bars.register_obj "o1" (o1 :> bar); > Bars.register_obj "o2" (o2 ); > print_endline ("calling o1: " ^ (Bars.get_obj "o1")#hello); > print_endline ("calling o2: " ^ (Bars.get_obj "o2")#hello) >=20 >=20 >=20 >=20 > The List_fns.Registry functor will create a monomorphic registry for the > specified base type. >=20 >=20 > Probably, this may help you :) >=20 > Best wishes, > Ivan Gotovchits >=20 > On Wed, Feb 22, 2017 at 12:38 PM, Richard W.M. Jones >=20 > wrote: > > On Wed, Feb 22, 2017 at 06:28:51PM +0100, Damien Guichard wrote: > > > Hi Richard. > > >=20 > > > Is this the code you want ? > > >=20 > > > type 'a obj_list =3D 'a list > > > constraint 'a =3D < hello : string; .. > as 'a > >=20 > > Perhaps. Is it possible to write the list_fns.mli interface > > using this? > >=20 > > Rich. > >=20 > >=20 > > -- > > Caml-list mailing list. Subscription management and archives: > > https://sympa.inria.fr/sympa/arc/caml-list > > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > Bug reports: http://caml.inria.fr/bin/caml-bugs --=20 Mikhail Mandrykin Linux Verification Center, ISPRAS web: http://linuxtesting.org e-mail: mandrykin@ispras.ru