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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id F41A17EC41 for ; Wed, 24 Oct 2012 21:32:35 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of madroach@gmerlin.de) identity=pra; client-ip=80.91.229.3; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gclci-caml-list@m.gmane.org"; x-sender="madroach@gmerlin.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of gclci-caml-list@m.gmane.org designates 80.91.229.3 as permitted sender) identity=mailfrom; client-ip=80.91.229.3; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gclci-caml-list@m.gmane.org"; x-sender="gclci-caml-list@m.gmane.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of postmaster@plane.gmane.org designates 80.91.229.3 as permitted sender) identity=helo; client-ip=80.91.229.3; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gclci-caml-list@m.gmane.org"; x-sender="postmaster@plane.gmane.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQDADhBiFBQW+UDgWdsb2JhbABEi2i2EiMBARYmJ4IeAQEEAScTRAsLGC4hNhkbh1cDCQqzBA2JVIp6Z4NJgyQDlB6BVIsqiAE X-IronPort-AV: E=Sophos;i="4.80,642,1344204000"; d="scan'208";a="160286789" Received: from plane.gmane.org ([80.91.229.3]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 24 Oct 2012 21:32:32 +0200 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1TR6gu-0002Ay-8E for caml-list@inria.fr; Wed, 24 Oct 2012 21:32:36 +0200 Received: from stgt-d9be5a7a.pool.mediaways.net ([217.190.90.122]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Oct 2012 21:32:36 +0200 Received: from madroach by stgt-d9be5a7a.pool.mediaways.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Oct 2012 21:32:36 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Christopher Zimmermann Date: Wed, 24 Oct 2012 21:32:13 +0200 Message-ID: <20121024213213.2e447165b7c4ea9ad9d8e154@gmerlin.de> References: <20121024200310.9c639f43a97263423e113500@gmerlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: stgt-d9be5a7a.pool.mediaways.net In-Reply-To: X-Mailer: Sylpheed 3.2.0 (GTK+ 2.24.13; x86_64-unknown-openbsd5.2) X-Newsreader: Sylpheed 3.2.0 (GTK+ 2.24.13; x86_64-unknown-openbsd5.2) X-Validation-by: madroach@gmerlin.de Subject: [Caml-list] Re: typing mutually recursive classes On Wed, 24 Oct 2012 20:40:27 +0200 Gabriel Scherer wrote: > I don't really understand what you are trying to achieve with this > #foo types. It's the simplest statement possible to demonstrate the typing error I ran into. Even simpler: class type a = object end and b = object method foo: 'a. (#a as 'a) -> unit end fails, but class type a = object end class type b = object method foo: 'a. (#a as 'a) -> unit end works fine. Why? > What would even be the type of "set" in your example? You > cannot hold a mutable reference to a polymorphic type (#element list), > so I'm not sure what you would have but (element list). That's correct. It should read val mutable set = [] method register :'a. (#element as 'a) -> unit = fun s -> set <- (s : #element :> element) :: set > If you're > going to coerce your elements into the common (element) supertype > anyway, why insist on having flexible bounds? You could just use > (registry) and (element), coerce when needed (foo :> element), and get > rid of those pesky typing issues. That's my current workaround for this issue. But I would prefer a solution where the coercion happens in the registry. > > On Wed, Oct 24, 2012 at 8:03 PM, Christopher Zimmermann > wrote: > > Hi, > > > > I have a problem with typing a system of mutually recursive classes. > > > > This piece of code fails to compile: > > > > class a = > > object end > > and b = > > object > > method foo: a -> int = > > fun s -> 3 > > end;; > > > > Error: The universal type variable 'a cannot be generalized: > > it escapes its scope. > > > > > > But this compiles fine: > > > > class a = > > object end > > class b = > > object > > method foo: 'a. (#a as 'a) -> int = > > fun s -> 3 > > end;; > > > > > > What I actually want to do is this: > > > > class element id (registry :#registry) = > > object > > method registry = registry > > end > > > > and registry = > > object > > val set = [] > > method register :'a. (#element as 'a) -> unit = > > fun s -> > > set <- s :: set > > end > > > > > > Any ideas how to do this without parametrizing the classes? > > > > Christopher