From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 844247ED25 for ; Sat, 20 Jul 2013 21:01:45 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=pra; client-ip=131.111.8.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=mailfrom; client-ip=131.111.8.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@ppsw-32.csi.cam.ac.uk) identity=helo; client-ip=131.111.8.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="postmaster@ppsw-32.csi.cam.ac.uk"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhQCAMLd6lGDbwiElGdsb2JhbABaxFyBFBYOAQEBAQcNCQkUBSOCJAEBAQMBJxM/BQsLISUPAQRDBhOHfgMJBgStbSJCiAeQD4QFA5ddlGA X-IPAS-Result: AhQCAMLd6lGDbwiElGdsb2JhbABaxFyBFBYOAQEBAQcNCQkUBSOCJAEBAQMBJxM/BQsLISUPAQRDBhOHfgMJBgStbSJCiAeQD4QFA5ddlGA X-IronPort-AV: E=Sophos;i="4.89,709,1367964000"; d="scan'208";a="26733134" Received: from ppsw-32.csi.cam.ac.uk ([131.111.8.132]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 Jul 2013 21:01:44 +0200 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from cpc2-cmbg14-2-0-cust33.5-4.cable.virginmedia.com ([86.26.0.34]:46376 helo=study.localdomain) by ppsw-32.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.156]:587) with esmtpsa (PLAIN:lpw25) (TLSv1.2:DHE-RSA-AES128-SHA:128) id 1V0cPY-0006P7-1m (Exim 4.80_167-5a66dd3) (return-path ); Sat, 20 Jul 2013 20:01:44 +0100 From: Leo White To: Goswin von Brederlow Cc: caml-list@inria.fr References: <20130720131249.GA32103@frosties> X-Face: "XWxb[u_Z\PA_Y?9@|IA!!+jTb(/290-*ea/Un$I0B98.$n%eL.;2w*,z]WR#T:,p[ NBd++M7l]#7zj7!{~iw $W-"/=|dVjhT[D{4~gE}gK<2`.6fs!;uqqud]vs2N/3^m7{aS1V, Date: Sat, 20 Jul 2013 20:06:43 +0100 Message-ID: <87bo5xcapo.fsf@study.localdomain> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Caml-list] implicit subtyping fails with recursive classes I am not sure, but I think the problem is that you are using #foo before it is fully defined, so it is becoming unified with the universal 'a and then when #foo is generalised the universal is escaping its scope. One way to avoid the problem is to expand out the type of #foo: # class type t = object method push : 'b. (< foo : t -> unit; ..> as 'b) -> unit end;; class type t = object method push : < foo : t -> unit; .. > -> unit end # class type foo = object method foo : t -> unit end;; class type foo = object method foo : t -> unit end if foo has a lot of methods, and you want to avoid typing them out multiple times, you could try: # class type ['a] foo' = object method foo : 'a -> unit end;; class type ['a] foo' = object method foo : 'a -> unit end # class type t = object method push : 'b. (t #foo' as 'b) -> unit end;; class type t = object method push : t #foo' -> unit end # class type foo = [t] foo';; class type foo = [t] foo' Regards, Leo Goswin von Brederlow writes: > Hi, > > I'm trying to add implicit subtyping to a pair of recurisve classes: > > Without subtyping: > ------------------ > class type foo = object method foo : t -> unit end > and t = object method push : foo -> unit end > > With that I can call t#push (x :> foo) for any x that implements the > foo interface. > > > What I want: > ------------ > # class type foo = object method foo : t -> unit end > and t = object method push : 'a . (#foo as 'a) -> unit end;; > ^^^^^^^^^^^^^^^^^^^^^^^^^ > Error: The universal type variable 'a cannot be generalized: > it escapes its scope. > > > > The problem seems to be the recursive definition with "and". Here is > an example with and without "and": > > (* works *) > class type foo = object method foo : string end;; > class type bar = object inherit foo method bar : string end;; > class type t = object method push : 'a . (#foo as 'a) -> unit end;; > > (* fails *) > class type foo = object method foo : string end > and bar = object inherit foo method bar : string end > and t = object method push : 'a . (#foo as 'a) -> unit end;; > > > So what am I doing wrong? > > MfG > Goswin