Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] A class that contains instances of itself?
@ 2002-01-05 12:45 wrader
  2002-01-05 13:15 ` John Prevost
  2002-01-05 13:16 ` Alain Frisch
  0 siblings, 2 replies; 4+ messages in thread
From: wrader @ 2002-01-05 12:45 UTC (permalink / raw)
  To: caml-list

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


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

end of thread, other threads:[~2002-01-07  9:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-05 12:45 [Caml-list] A class that contains instances of itself? wrader
2002-01-05 13:15 ` John Prevost
2002-01-05 13:16 ` Alain Frisch
2002-01-05 23:27   ` [Caml-list] IMAP library for Caml? Will Benton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox