Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] A class that contains instances of itself?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-01-05 (12:46)
From: wrader@O...
Subject: [Caml-list] A class that contains instances of itself?
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 = 
    var mutable anotherInstanceOfSomeClass ???????

    method talk () =

    method setInstance x = 
      anotherInstanceOfSomeClass <- x

    method useInstance () =
      if anotherInstanceOfSomeClass is set to a
      usable value, then do
        do nothing

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


Walter Rader
Bug reports:  FAQ:
To unsubscribe, mail  Archives: