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 40E257F616 for ; Wed, 22 Feb 2017 18:01:14 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=rich@annexia.org; spf=Pass smtp.mailfrom=rich@annexia.org; spf=Pass smtp.helo=postmaster@annexia.org Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of rich@annexia.org) identity=pra; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of rich@annexia.org designates 80.68.91.176 as permitted sender) identity=mailfrom; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@annexia.org designates 80.68.91.176 as permitted sender) identity=helo; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="postmaster@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" IronPort-PHdr: =?us-ascii?q?9a23=3Ajj54bx9KaLO0lf9uRHKM819IXTAuvvDOBiVQ1KB+?= =?us-ascii?q?1OwcTK2v8tzYMVDF4r011RmSDNidsqwP2ree8/i5HzdfsdDZ6DFKWacPfiFGoP?= =?us-ascii?q?1epxYnDs+BBB+zB9/RRAt+Iv5/UkR49WqwK0lfFZW2TVTTpnqv8WxaQU2nZkIm?= =?us-ascii?q?btjyT4XbisDy0+Gp57XSZR9JjXyze+BcNhKz+E/rt8IWiJFuYpl3712BgHxOdv?= =?us-ascii?q?8cjTdyJFmTtx/64Mqg/Zcl9D5f7aFyv/VcWLn3KvxrBYdTCy4rZjg4?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0ABCQBtw61Y/7BbRFBeHgYMGQYMgyYnO?= =?us-ascii?q?oEJgw2aagIBFQEBAQEBAQaBHpdFIokHQxQBAQEBAQEBAQEBAWEogjMggksTexM?= =?us-ascii?q?hBSiIPAOBXRGecpFxOot3hgc7ihmCaIIxBYkShjqMRAGBUIUjiyKRHZMlNiGBA?= =?us-ascii?q?GEIPoN7DAGCQUA1ihQBAQE?= X-IPAS-Result: =?us-ascii?q?A0ABCQBtw61Y/7BbRFBeHgYMGQYMgyYnOoEJgw2aagIBFQE?= =?us-ascii?q?BAQEBAQaBHpdFIokHQxQBAQEBAQEBAQEBAWEogjMggksTexMhBSiIPAOBXRGec?= =?us-ascii?q?pFxOot3hgc7ihmCaIIxBYkShjqMRAGBUIUjiyKRHZMlNiGBAGEIPoN7DAGCQUA?= =?us-ascii?q?1ihQBAQE?= X-IronPort-AV: E=Sophos;i="5.35,195,1484002800"; d="scan'208";a="261679619" Received: from annexia.org ([80.68.91.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 22 Feb 2017 18:01:02 +0100 Received: from rich by annexia.org with local (Exim 4.84_2) (envelope-from ) id 1cgaHl-0001s1-Gx for caml-list@inria.fr; Wed, 22 Feb 2017 17:01:01 +0000 Date: Wed, 22 Feb 2017 17:01:01 +0000 From: "Richard W.M. Jones" To: caml-list@inria.fr Message-ID: <20170222170101.GE28111@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Subject: [Caml-list] List of structurally typed objects 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.