caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] implicit subtyping fails with recursive classes
@ 2013-07-20 13:12 Goswin von Brederlow
  2013-07-20 19:06 ` Leo White
  0 siblings, 1 reply; 3+ messages in thread
From: Goswin von Brederlow @ 2013-07-20 13:12 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-23 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-20 13:12 [Caml-list] implicit subtyping fails with recursive classes Goswin von Brederlow
2013-07-20 19:06 ` Leo White
2013-07-23 11:54   ` Goswin von Brederlow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).