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 C58527F616 for ; Wed, 22 Feb 2017 18:10:19 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qk0-f180.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.220.180; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.220.180 as permitted sender) identity=mailfrom; client-ip=209.85.220.180; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; 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-qk0-f180.google.com) identity=helo; client-ip=209.85.220.180; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-qk0-f180.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AxdBzWB2i1dIZhF0hsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?seIfIvad9pjvdHbS+e9qxAeQG96KtrQd1aGH7ujJYi8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6?= =?us-ascii?q?JvjvGo7Vks+7y/2+94fdbghMhDexe65+IRS5oQjVtsQdnJdvJLs2xhbVuHVDZv?= =?us-ascii?q?5YxXlvJVKdnhb84tm/8Zt++ClOuPwv6tBNX7zic6s3UbJXAjImM3so5MLwrhnM?= =?us-ascii?q?URGP5noHXWoIlBdDHhXI4wv7Xpf1tSv6q/Z91SyHNsD4Ubw4RTKv5LpwRRT2lC?= =?us-ascii?q?kIKSI28GDPisxxkq1bpg6hpwdiyILQeY2ZKeZycr/Ycd4cQmVPQ9tRVzdZAoyi?= =?us-ascii?q?c4QPE+QPPeFdr4bnplsOqwa1CQ2jCe7rzzNFgGL9068n3OQ7CQzJ3gIgEdIAvn?= =?us-ascii?q?rXsdv7KrsdXPupzKXU1zjPc+9a1Sv/5YXObxsvoeuMXbV1ccfJyEcgDRjKjk+R?= =?us-ascii?q?qYP7OzOey/kDvHSb7+V+T+KglXQnoBx2rzig3MgjkZPJhoMLxVDA7yl525o6Jd?= =?us-ascii?q?2mR05hf9GkCoBdty6fN4RsQ8MiR3tktzo9yr0DoJO2ejUBxpogxx7acfOHco6I?= =?us-ascii?q?7wriVOaXOzd4hWhqdKixhxao6UShyvfzVsmz0FZNtCZKjt7MtnUL2hfO6caHUu?= =?us-ascii?q?Nw8lm91TuLzQze6eFJLVoqmabFN5It2KM8m5kPvUnFAyT4gl/5jLWMeUUh4uWo?= =?us-ascii?q?6/roYrHhppKEMo97kAD+MqA3lsymAuQ0LhECX2aG9em/yLHv50L5QLJNjv05lq?= =?us-ascii?q?nWrorWKtgcpq68GwNV04Aj5AijDzq+ztgUgX0KIEhGdR+HlYTlJU/CLOziAfui?= =?us-ascii?q?gFmgjC9nx/XcMb3gBpXNIGLDkLDkfbtl5E5T0hE8zcpe551KDrENOunzVVPxtN?= =?us-ascii?q?PGFB82LRa0zv3oCNV4zIweWGaPDrWFP6PVtF+E/vgvLPWUZI8JpDb9LOAo6OL0?= =?us-ascii?q?gn88nV8RZK2p3ZoMaHCkBflmOEWYYX/0gtgbC2sKvww+TPbriFKYSzJTaWyyDO?= =?us-ascii?q?oA4WRxMoOtDY7ZSsiSxpnHlAW8GJBNLCgSEFGHEV/hcYOJS/YFLiWILZkyvCYD?= =?us-ascii?q?UO2OQoU71Byq/DTxy7d9I/CcriIRv4ji2dwz/ObTmAs/7xR7Cs2c1yeGSGQizT?= =?us-ascii?q?BAfCM/wK0q+R818VyEy6UtxqEBGA=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0B7AgCHxa1YhrTcVdFeGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFgEBAQMBAQEJAQEBg0g/gQkHg1SbYoI6hkCEA4pEKoV4AoJ+B0MUAQE?= =?us-ascii?q?BAQEBAQEBAQESAQEBCAsLCh0vgjMighwBBSMEGQEbEgsBAwwGBQsNAgIJHQICI?= =?us-ascii?q?gERAQUBChIGEwgKh3YDgVEBAxUOojU/jAOBbBgFARyDCQWDaAoZJwMKVYMiAQE?= =?us-ascii?q?BAQEBBAEBAQEBARoCBhJ5hUGEb4dagl8FhzgMgU6GOn+LRYIChHKLL4JOjkKRX?= =?us-ascii?q?hQegRU2gSEhFB9TF4QlIIILIjWKFAEBAQ?= X-IPAS-Result: =?us-ascii?q?A0B7AgCHxa1YhrTcVdFeGgEBAQECAQEBAQgBAQEBFgEBAQM?= =?us-ascii?q?BAQEJAQEBg0g/gQkHg1SbYoI6hkCEA4pEKoV4AoJ+B0MUAQEBAQEBAQEBAQESA?= =?us-ascii?q?QEBCAsLCh0vgjMighwBBSMEGQEbEgsBAwwGBQsNAgIJHQICIgERAQUBChIGEwg?= =?us-ascii?q?Kh3YDgVEBAxUOojU/jAOBbBgFARyDCQWDaAoZJwMKVYMiAQEBAQEBBAEBAQEBA?= =?us-ascii?q?RoCBhJ5hUGEb4dagl8FhzgMgU6GOn+LRYIChHKLL4JOjkKRXhQegRU2gSEhFB9?= =?us-ascii?q?TF4QlIIILIjWKFAEBAQ?= X-IronPort-AV: E=Sophos;i="5.35,195,1484002800"; d="scan'208";a="214383765" Received: from mail-qk0-f180.google.com ([209.85.220.180]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 22 Feb 2017 18:10:18 +0100 Received: by mail-qk0-f180.google.com with SMTP id s186so8752883qkb.1 for ; Wed, 22 Feb 2017 09:10:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ReidnLLAX2JBc1Kek0llM0pdLPULa1QTeQ1BTv2jNfU=; b=B+9KRgkhPqve3YBTvq0RoO3CRL/OATJovd2sS7hvfKQn/lZNioNGYbP3Gws6NIzlSt bNOd5BybHSfVSHny65lNpfcXLWI/cA170JApNFZi1vRE1/se/FWwMHNgxzP8H1m4dYB6 Ar5b/qzrrPsmVH/lW5G2I4psUSFO+XKI1F2BfcWALcO4eMDWME3euso2GuBHTquP7aaq LwSwWXNN0scyl1MPIPE6+YcU+zTVzmRE2wMBfxuRnwkQMdbZHd79yMIpBBxzvE5gSEho Rk9Iw4a69aFrNnDDIxgqtIv3gC2AHM1NiQS7QpNhf5cJ/bAIG/M3AJvsisiSSxvgDX2b +w9w== 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=ReidnLLAX2JBc1Kek0llM0pdLPULa1QTeQ1BTv2jNfU=; b=MXOpF01qwhlL/nqyW0kf6sMZo4Pg/MvFYeKyFnqm+5p7729mMS8oPV+IWZB2LSuNK6 a2CnwsVhYmoKz4r0QVP1Xx7oHvSSOPPkI8+Zn27dnELIftVBI76iQ/YgI9IHg+SNZPMq 0sITCP1N25n+lT1udLSjSK1PjIDRJ4YUHJv4gHeoqOeas/5jnXBjEwefB6nb359828my FyujEEfB8fKrqtBJqDSDFYsL0rC9hdEvin76vxJgByXKQHhddTYLE53S3rFWHa03ynh2 fYgp+QbDvETY+SH61s0O4GLoJquBX5PwtRvmHtStU2KZiJiQ31Y0myjpqMy37d0KVK+E iPZw== X-Gm-Message-State: AMke39myGWRkg6XL13GoMiCzfkswuvFRY5Y0NnK25YGCb+rdwxbhjLQc1pBWp7z9GjUKvgZe5c2LF6X2OTMeYg== X-Received: by 10.55.31.222 with SMTP id n91mr29694737qkh.212.1487783417527; Wed, 22 Feb 2017 09:10:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.177.154 with HTTP; Wed, 22 Feb 2017 09:09:37 -0800 (PST) In-Reply-To: <20170222170101.GE28111@annexia.org> References: <20170222170101.GE28111@annexia.org> From: Gabriel Scherer Date: Wed, 22 Feb 2017 12:09:37 -0500 Message-ID: To: "Richard W.M. Jones" Cc: caml users Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] List of structurally typed objects The signature you demand is actually incorrect, because the return type of get_obj is to permissive: it claims that it can return *any* ('a obj), so you could register an object with just the hello method and get back an object with more methods. On the other hand, if you use the monomorphic < hello : string > type in the interface, then it is type-correct and the implementation you provide is accepted. It is explicit in the fact that you can't recover the extra methods of the object once they have been stored in this lowest-common-denominator container. On Wed, Feb 22, 2017 at 12:01 PM, Richard W.M. Jones wrote: > 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. > > -- > 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