caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: [Caml-list] implicit subtyping fails with recursive classes
Date: Sat, 20 Jul 2013 15:12:49 +0200	[thread overview]
Message-ID: <20130720131249.GA32103@frosties> (raw)

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


             reply	other threads:[~2013-07-20 13:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-20 13:12 Goswin von Brederlow [this message]
2013-07-20 19:06 ` Leo White
2013-07-23 11:54   ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130720131249.GA32103@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).