Using modules and classes recursively

From: Markus Mottl (mottl@miss.wu-wien.ac.at)
Date: Sat Jan 09 1999 - 21:24:39 MET


From: Markus Mottl <mottl@miss.wu-wien.ac.at>
Message-Id: <199901092024.VAA15046@miss.wu-wien.ac.at>
Subject: Using modules and classes recursively
To: caml-list@inria.fr (OCAML)
Date: Sat, 9 Jan 1999 21:24:39 +0100 (MET)

Hello - Bonjour,

Even though I have tried hard, I couldn't solve the following problem:

I want to have a class that is able to return a set of objects of
its type, but I have no idea, how I have to formulate this (if it is
possible).

E.g.:

---------------------------------------------------------------------------
class foo =
object
  method bar = FooSet.singleton (new foo)
end
---------------------------------------------------------------------------

An object of this class would return a set containing itself if its
member function "bar" is called.
Before the definition of this class, the module "FooSet" has to be
created. But it seems impossible to do so.

E.g.:

---------------------------------------------------------------------------
module FooSet =
  Set.Make (struct type t = <bar : FooSet.t> let compare = compare end)
---------------------------------------------------------------------------

This does not work, because the type constructor "FooSet.t" cannot be
bound before "FooSet" exists - but that's what are defining!

Is it impossible to have modules and classes combined recursively?
If yes, what would be a good workaround?

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:17 MET