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 5F9137F616 for ; Wed, 22 Feb 2017 18:28:46 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=alphablock@orange.fr; spf=None smtp.mailfrom=alphablock@orange.fr; spf=None smtp.helo=postmaster@smtp.smtpout.orange.fr Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of alphablock@orange.fr) identity=pra; client-ip=80.12.242.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="alphablock@orange.fr"; x-sender="alphablock@orange.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of alphablock@orange.fr) identity=mailfrom; client-ip=80.12.242.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="alphablock@orange.fr"; x-sender="alphablock@orange.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.smtpout.orange.fr) identity=helo; client-ip=80.12.242.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="alphablock@orange.fr"; x-sender="postmaster@smtp.smtpout.orange.fr"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AMoozhBbhB/pMtBcRtycvBGz/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZpsu/bnLW6fgltlLVR4KTs6sC0LuL9fm+Ej1QqdbZ6TZZL8wKD0dEwe?= =?us-ascii?q?wt3CUeQ+e9QXXhK/DrayFoVO9jb3RCu0+BDE5OBczlbEfTqHDhpRQbGxH4KBYn?= =?us-ascii?q?br+tQt2a3IyL0LW58pjXJgFJnyaVYLVoLRzwox+CmNMRhN5OI6Mwxx2BjWZJcO?= =?us-ascii?q?Rf328gcVuXhxb17MO3951L9D5Zvf0sscBaB/apN58kRKBVWWx1e1s+49fm4EHO?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AXCgBUya1Yh4TyDFBeHAEBBAEBCgEBG?= =?us-ascii?q?AEFAQsBg3wLAydfjlWPPgEBBphjIoYAAoNIFAEBAQEBAQEBAQEBEgEBAQgNCQo?= =?us-ascii?q?dL4IzIIIeBicLAQVRC0ZXEwgCiAQDgVEBCxGwezqGdgGETjKGB4JKgmqFIIUZB?= =?us-ascii?q?YkShjqGGoYqa4YJiy+EGYYshkuLHogHNoEhNSNPhFyBbnSKFAEBAQ?= X-IPAS-Result: =?us-ascii?q?A0AXCgBUya1Yh4TyDFBeHAEBBAEBCgEBGAEFAQsBg3wLAyd?= =?us-ascii?q?fjlWPPgEBBphjIoYAAoNIFAEBAQEBAQEBAQEBEgEBAQgNCQodL4IzIIIeBicLA?= =?us-ascii?q?QVRC0ZXEwgCiAQDgVEBCxGwezqGdgGETjKGB4JKgmqFIIUZBYkShjqGGoYqa4Y?= =?us-ascii?q?Jiy+EGYYshkuLHogHNoEhNSNPhFyBbnSKFAEBAQ?= X-IronPort-AV: E=Sophos;i="5.35,195,1484002800"; d="scan'208";a="261683840" Received: from smtp10.smtpout.orange.fr (HELO smtp.smtpout.orange.fr) ([80.12.242.132]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 22 Feb 2017 18:28:45 +0100 Received: from [192.168.1.10] ([86.209.187.227]) by mwinf5d45 with ME id ntUk1u0014uobna03tUlnm; Wed, 22 Feb 2017 18:28:45 +0100 X-ME-Helo: [192.168.1.10] X-ME-Auth: YWxwaGFibG9ja0B3YW5hZG9vLmZy X-ME-Date: Wed, 22 Feb 2017 18:28:45 +0100 X-ME-IP: 86.209.187.227 To: caml-list@inria.fr References: <20170222170101.GE28111@annexia.org> From: Damien Guichard Message-ID: <61e8bf6f-4abc-26e7-7b0b-ce935faaf8b8@orange.fr> Date: Wed, 22 Feb 2017 18:28:51 +0100 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46 MIME-Version: 1.0 In-Reply-To: <20170222170101.GE28111@annexia.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Validation-by: alphablock@orange.fr Subject: Re: [Caml-list] List of structurally typed objects Hi Richard. Is this the code you want ? type 'a obj_list = 'a list constraint 'a = < hello : string; .. > as 'a hope it helps, Damien Guichard (SpiceGuid) Richard W.M. Jones a écrit : > Is it possible to construct a list of structurally typed ("duck > typed") objects? > > The code below seems as if superficially it should work, at least as > far as I understand the OCaml memory model and how objects work > internally. However the implementation doesn't match the interface. > > ------ list_fns.mli ---------------------------- > type 'a obj = < hello : string; .. > as 'a > val register_obj : string -> 'a obj -> unit > val get_obj : string -> 'a obj > ------------------------------------------------ > > ------ list_fns.ml ----------------------------- > type 'a obj = < hello : string; .. > as 'a > let objs = ref [] > let register_obj name obj = objs := (name, obj) :: !objs > let get_obj name = List.assoc name !objs > ------------------------------------------------ > > $ ocamlc -c list_fns.mli > $ ocamlc -c list_fns.ml > File "list_fns.ml", line 1: > Error: The implementation list_fns.ml > does not match the interface list_fns.cmi: > Values do not match: > val register_obj : string -> '_a -> unit > is not included in > val register_obj : string -> < hello : string; .. > obj -> unit > File "list_fns.ml", line 3, characters 4-16: Actual declaration > > I'm guessing that "constraint" should be used here, but how? > > Rich. >