Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* creating fresh objects of type 'self
@ 1999-04-09 22:56 Markus Mottl
  1999-04-12  8:33 ` Didier Remy
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Mottl @ 1999-04-09 22:56 UTC (permalink / raw)
  To: OCAML

Hello,

is there a convenient way of creating objects of type 'self in classes?

Cloning is easy, e.g:

  class foo = object
    method clone = {< >}
  end

which yields an object not necessarily of type "foo" but possibly of
a subclass.

But I wonder, how I can do something similar to get a "fresh" object.
I would like to be able to have something like:

  class foo = object (_ : 'self)
    method create = new 'self
  end

The only possibility I know to get the intended result is rather
inconvenient: I do as in "clone", but reinitialize all member data with
their initial data. This is not only error-prone, but possibly quite a
lot of work.

Am I overseeing an obvious short solution?

The original idea is to have a parent *object* passing "self" to a child
*object* it has just created itself (note that I mean concrete objects,
not classes).

Best regards,
Markus Mottl

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




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

end of thread, other threads:[~1999-04-12 17:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-09 22:56 creating fresh objects of type 'self Markus Mottl
1999-04-12  8:33 ` Didier Remy
1999-04-12 12:03   ` Markus Mottl
1999-04-12 10:39     ` Didier Remy
1999-04-12 13:10       ` Markus Mottl

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