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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 8B2FF7EC41 for ; Wed, 24 Oct 2012 20:41:09 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.182 as permitted sender) identity=mailfrom; client-ip=209.85.223.182; receiver=mail1-smtp-roc.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 (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f182.google.com) identity=helo; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ie0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgoCAPk0iFDRVd+2m2dsb2JhbABEr2+SAggjAQEBAQEICQsJFCeCHgEBAQQSAhMZARsSCwEDDAYFCwMKDSEiAREBBQEKEgYTEhCHTwEDDwudGWAJA4wognaFBQoZJwMKWYh1AQUMi1WGbQOVc4EXjUEWKYQT X-IronPort-AV: E=Sophos;i="4.80,640,1344204000"; d="scan'208";a="178786733" Received: from mail-ie0-f182.google.com ([209.85.223.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Oct 2012 20:41:08 +0200 Received: by mail-ie0-f182.google.com with SMTP id k10so2089084iea.27 for ; Wed, 24 Oct 2012 11:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=sUEPwZo4yOtjVOnha10nEGQQ4RgIxJTLkvn4X64e+Sw=; b=tYvixwadye0p9hh+spIbgD0v2C28utXGVldP4V/bsDPM6CNXirv0gPBuDbs9B3lO8Y JsZCClMzAEGru+kJUoGj6IvpNRpalg0FbVN1D7tnxNRlmylI2zvQwqfIpUZ42zDxq9Xe eaX4b17rqQH2+eRMj9xQF9ZLAbJQEYT/W3Z81FN2VARLyFENdZQ2oigx6dvSMpF1Sn/O lB11fXAuCeeCsc27zYLGCHpOrHhSv0pT1iE5KzHqrniYxe2WLRS+nXp6+qfxFZqJqJ3d aLf/vEmWgPLmUjp4H4IjAImujClvXgfH/tpbcbn7ENvO0JHl62jd5AQU0K1B6Nzvj4zl q86Q== Received: by 10.50.1.170 with SMTP id 10mr3553228ign.2.1351104067754; Wed, 24 Oct 2012 11:41:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.65.9 with HTTP; Wed, 24 Oct 2012 11:40:27 -0700 (PDT) In-Reply-To: <20121024200310.9c639f43a97263423e113500@gmerlin.de> References: <20121024200310.9c639f43a97263423e113500@gmerlin.de> From: Gabriel Scherer Date: Wed, 24 Oct 2012 20:40:27 +0200 Message-ID: To: Christopher Zimmermann Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] typing mutually recursive classes I don't really understand what you are trying to achieve with this #foo types. 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). 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. 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 > > > -- > 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