caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] typing mutually recursive classes
@ 2012-10-24 18:03 Christopher Zimmermann
  2012-10-24 18:40 ` Gabriel Scherer
  0 siblings, 1 reply; 6+ messages in thread
From: Christopher Zimmermann @ 2012-10-24 18:03 UTC (permalink / raw)
  To: caml-list

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


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

end of thread, other threads:[~2012-10-24 21:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-24 18:03 [Caml-list] typing mutually recursive classes Christopher Zimmermann
2012-10-24 18:40 ` Gabriel Scherer
2012-10-24 19:32   ` [Caml-list] " Christopher Zimmermann
2012-10-24 20:35     ` Didier Cassirame
2012-10-24 21:30       ` Didier Cassirame
     [not found]     ` <CAPFanBHdh8xKsZC6fs2oXEOitjKLhZzVUdVmYT+6d0jL46YM0w@mail.gmail.com>
2012-10-24 21:04       ` [Caml-list] " Gabriel Scherer

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).