Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Alain Frisch <frisch@c...>
Subject: Re: [Caml-list] A class that contains instances of itself?
On Sat, 5 Jan 2002 wrader@ocf.berkeley.edu wrote:

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

What about :

class someClass =
object(_ : 'self)
  val mutable anotherInstanceOfSomeClass : 'self option = None

  method talk () =
    print_string("Hello.\n")

  method setInstance x =
    anotherInstanceOfSomeClass <- Some x

  method useInstance () =
    match anotherInstanceOfSomeClass with
      | Some a -> a # talk ()
      | None -> ()
end


?

-- 
  Alain

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