From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA17123; Sat, 5 Jan 2002 13:46:03 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA16998 for ; Sat, 5 Jan 2002 13:46:02 +0100 (MET) Received: from war.OCF.Berkeley.EDU (war.OCF.Berkeley.EDU [128.32.191.89]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g05Ck0D22866 for ; Sat, 5 Jan 2002 13:46:01 +0100 (MET) Received: from death.OCF.Berkeley.EDU (http@death.OCF.Berkeley.EDU [128.32.191.87]) by war.OCF.Berkeley.EDU (8.11.6/8.9.3) with ESMTP id g05Cjxp24150 for ; Sat, 5 Jan 2002 04:45:59 -0800 (PST) Date: Sat, 5 Jan 2002 04:45:59 -0800 (PST) Message-Id: <200201051245.g05Cjxp24150@war.OCF.Berkeley.EDU> Content-Disposition: inline Mime-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] A class that contains instances of itself? From: wrader@OCF.Berkeley.EDU Reply-To: wrader@OCF.Berkeley.EDU Content-Type: text/plain; charset=us-ascii X-Mailer: acmemail Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Please forgive me if there is an obvious answer to my question. I want to have an class that can contain instances of that same class. Assume something like this: (ignore any easy syntax errors - I'm making up this example right now) class someClass = object var mutable anotherInstanceOfSomeClass ??????? method talk () = print_string("Hello.\n") method setInstance x = anotherInstanceOfSomeClass <- x method useInstance () = if anotherInstanceOfSomeClass is set to a usable value, then do anotherInstanceOfSomeClass#talk else do nothing end;; One must call anotherInstanceOfSomeClass#setInstance before using anotherInstanceOfSomeClass#talk. What do I put in place of the ?????? to indicate that the value is not yet usable? I could create a "dummy" someClass object to use as the "NULL" value, let's say called someClassNULL. someClassNULL must already be defined if I use it in the body of someClass, but I can't create it before the definition of someClass because the compiler doesn't know what someClass _is_ yet. Catch-22!! I've been staring at this problem for hours, so any help would be fantastic! (If only I spoke French and could read the many books available about OCaml...) Thanks, Walter Rader ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr