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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 441E57F616 for ; Wed, 22 Feb 2017 19:08:30 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=ivg@ieee.org; spf=Pass smtp.mailfrom=ivg@ieee.org; spf=None smtp.helo=postmaster@mail-it0-f52.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ivg@ieee.org) identity=pra; client-ip=209.85.214.52; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of ivg@ieee.org designates 209.85.214.52 as permitted sender) identity=mailfrom; client-ip=209.85.214.52; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-it0-f52.google.com) identity=helo; client-ip=209.85.214.52; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="postmaster@mail-it0-f52.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A1gb4eRPn4PPsMkTJCnEl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0Ivv7rarrMEGX3/hxlliBBdydsKMZzbOI+Pm4BiQp2tWoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7?= =?us-ascii?q?Ovr6GpLIj8Swyuu+54Dfbx9GiTe5Yb5+Ngi6oATeusULnYdvKLs6xwfUr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JyJDtS3gbeB9C69GJBGZ2kADUqDRyTGbYKBDtYSYSTaDch9lSIP?= =?us-ascii?q?Vbm9UMd11A+hnA73xrchKfDbrH5L/an/3cR4srWA3So58iZ5WoHAimw=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AHAgB30q1YhjTWVdFeGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFQEBAQECAQEBAQgBAQEBhAeBCQeDVJtigjqNToc5KoV4AoJ/B0MUAQE?= =?us-ascii?q?BAQEBAQEBAQESAQEBCAsLCh0vgjMighsBAQEDASMEGQEBLAsBBAsLCw0NHQICI?= =?us-ascii?q?hIBBQEKEgYTEolLAwgFCA6iWD+LG2iBbDqDCAEBBYQvA4N0AQEBAQEFAQEBAQE?= =?us-ascii?q?BARkIEoY6hG+FAYJZgl+HPQyICH+FG4YqhnSLL4JOjkKKTIcSFB6BFQ8ngSFhC?= =?us-ascii?q?D4XBYN2KiCCCyI1AYoTAQEB?= X-IPAS-Result: =?us-ascii?q?A0AHAgB30q1YhjTWVdFeGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBhAeBCQeDVJtigjqNToc5KoV4AoJ/B0MUAQEBAQEBAQEBAQESA?= =?us-ascii?q?QEBCAsLCh0vgjMighsBAQEDASMEGQEBLAsBBAsLCw0NHQICIhIBBQEKEgYTEol?= =?us-ascii?q?LAwgFCA6iWD+LG2iBbDqDCAEBBYQvA4N0AQEBAQEFAQEBAQEBARkIEoY6hG+FA?= =?us-ascii?q?YJZgl+HPQyICH+FG4YqhnSLL4JOjkKKTIcSFB6BFQ8ngSFhCD4XBYN2KiCCCyI?= =?us-ascii?q?1AYoTAQEB?= X-IronPort-AV: E=Sophos;i="5.35,195,1484002800"; d="scan'208,217";a="214390999" Received: from mail-it0-f52.google.com ([209.85.214.52]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 22 Feb 2017 19:08:27 +0100 Received: by mail-it0-f52.google.com with SMTP id h10so137166263ith.1 for ; Wed, 22 Feb 2017 10:08:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=RLkNIVNnuCotvUiitfQCY5Cy2vfBz2g4bLOOsuD5TzM=; b=mkmXtK41RHEGfWShIu4I0EsHJeSdkP7xY2YeTlZmeJ9WwzU/0es8FYO2snP3q/q/Jq I8VtQeDzoXgjaCQwz4SqHsOTJHEPKz9aNlg2bikvsboLtSTyht1ifeaLPEcgCGpK1u1r QDn0L9hYLCj599op4kbvp13iSXjw1rmQ/fTyWuKfCJo6zabljXLF/wo1HnDIgF4bqxsN ZPLaEYUlPUuLe5g7kZGhSlbukZXNqKrj7JwJWhQ24dX/RVuhWe2gSpU4HtBT/SPB2r4Z uQ2QRO6ukwarPE0S5OGwBb+0Z5bXCIlfKboF3zhrTMM4VqnG2KIW3SDAJmcPblDluzY3 kY4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=RLkNIVNnuCotvUiitfQCY5Cy2vfBz2g4bLOOsuD5TzM=; b=beZeN63bldl6pReuPimN+wwnXp3XuPQfkqq5I1PdmqJyrebn4obGZR8R2rDMrMTfOj 8st2ZPZUSIgFMjb4yQdVajhhlkYaYe9AnJH3KPDASuoygNug3+DI8cL+LoUU4jIed10O Eze/dFF7SpO5+/aMLOgG7Xc7M63Aa9MuBH7QBqG5iQoJVpxFmOqucz1belEDxosp8TUO A1Fdq57RMoGban7Di+shA1Zx7G3BbhnPnLQp/SVSVAzAMQtgymDxdwtD9NNoaf4jyJ2e LIefTJmodVgEJ3Yf/LHW0NeZ8KfI2MA71IjcWak1SHs/Lpwx28iyRdIBMxVWfMpUiswW /g/g== X-Gm-Message-State: AMke39keXIW2gCQuAWtRmvUGCVvMfm+Zk9nKRoWOQShujDQuNoLaeGjjU9XfWxkMIm1YfHKaWmFU4B4R/0ZDYrra X-Received: by 10.36.5.67 with SMTP id 64mr3371360itl.97.1487786904036; Wed, 22 Feb 2017 10:08:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.46.224 with HTTP; Wed, 22 Feb 2017 10:08:23 -0800 (PST) In-Reply-To: <20170222173814.GG28111@annexia.org> References: <20170222170101.GE28111@annexia.org> <61e8bf6f-4abc-26e7-7b0b-ce935faaf8b8@orange.fr> <20170222173814.GG28111@annexia.org> From: Ivan Gotovchits Date: Wed, 22 Feb 2017 13:08:23 -0500 Message-ID: To: "Richard W.M. Jones" Cc: Damien Guichard , caml-list Content-Type: multipart/alternative; boundary=001a114398baeacc72054922613e Subject: Re: [Caml-list] List of structurally typed objects --001a114398baeacc72054922613e Content-Type: text/plain; charset=UTF-8 It is possible to generalize this approach using private row types. list_fns.mli: module Registry(Obj : sig type t = private < .. > end) : sig val register_obj : string -> Obj.t -> unit val get_obj : string -> Obj.t end list_fns.ml: module Registry(Obj : sig type t = private < .. > end) = struct let objs = ref [] let register_obj name obj = objs := (name, obj) :: !objs let get_obj name = List.assoc name !objs end test.ml: class foo = object method hello = "hello from foo" method goodbye () = print_endline "goodbye" end class bar = object method hello = "hello from bar" end module Bars = List_fns.Registry(struct type t = bar end) let () = let o1 = new foo in let o2 = 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) The List_fns.Registry functor will create a monomorphic registry for the specified base type. Probably, this may help you :) Best wishes, Ivan Gotovchits On Wed, Feb 22, 2017 at 12:38 PM, Richard W.M. Jones wrote: > On Wed, Feb 22, 2017 at 06:28:51PM +0100, Damien Guichard wrote: > > > > Hi Richard. > > > > Is this the code you want ? > > > > type 'a obj_list = 'a list > > constraint 'a = < hello : string; .. > as 'a > > Perhaps. Is it possible to write the list_fns.mli interface > using this? > > Rich. > > > -- > 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 > --001a114398baeacc72054922613e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
It is possible to generalize this approach using private r= ow types.=C2=A0

list_fns.mli:
module Registry(= Obj : sig
=C2=A0 =C2=A0 type t =3D private < .. >= ;
=C2=A0 end) : sig
=C2=A0 val re= gister_obj : string -> Obj.t -> unit
=C2=A0 val = get_obj : string -> Obj.t
end

list_fns.ml:
module Registry(Obj : sig
=C2=A0 =C2=A0 type t = =3D private < .. >
=C2=A0 end) =3D struct
<= /div>

=C2=A0 let objs =3D ref []
=C2=A0 let register_obj name obj =3D objs :=3D (name, obj) ::= !objs
=C2=A0 let get_obj name =3D List.assoc name !ob= js
end


class foo =3D obje= ct
=C2=A0 method hello =3D "hello from foo"<= /div>
=C2=A0 method goodbye () =3D print_endline "goodb= ye"
end

class bar =3D object
=C2=A0 method hello =3D &qu= ot;hello from bar"
end

<= /div>
module Bars =3D List_fns.Registry(struct type t =3D ba= r end)

let () =3D
=C2=A0 let o1 =3D new foo in
=C2=A0 let o2 = =3D new bar in
=C2=A0 Bars.register_obj "o1"= (o1 :> bar);
=C2=A0 Bars.register_obj "o2&quo= t; (o2 );
=C2=A0 print_endline ("calling o1: &quo= t; ^ (Bars.get_obj "o1")#hello);
=C2=A0 prin= t_endline ("calling o2: " ^ (Bars.get_obj "o2")#hello)<= /div>



T= he List_fns.Registry functor will create a monomorphic registry for the spe= cified base type.=C2=A0


Probabl= y, this may help you :)

Best wishes,
Ivan Gotovchits
=

On Wed, Feb= 22, 2017 at 12:38 PM, Richard W.M. Jones <rich@annexia.org> = wrote:
On Wed, Feb 22, 2= 017 at 06:28:51PM +0100, Damien Guichard wrote:
>
> Hi Richard.
>
> Is this the code you want ?
>
> type 'a obj_list =3D 'a list
> constraint 'a =3D < hello : string; .. > as 'a

Perhaps.=C2=A0 Is it possible to write the list_fns.mli interface
using this?

Rich.


--
Caml-list mailing list.=C2=A0 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

--001a114398baeacc72054922613e--