From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Didier.Remy@inria.fr
Cc: caml-list@inria.fr (OCAML)
Subject: Re: creating fresh objects of type 'self
Date: Mon, 12 Apr 1999 14:10:45 +0100 (MET DST) [thread overview]
Message-ID: <199904121210.OAA08612@miss.wu-wien.ac.at> (raw)
In-Reply-To: <19990412123905.09954@morgon.inria.fr> from "Didier Remy" at Apr 12, 99 12:39:05 pm
> You could use an initializer to remember the "fresh" state in an instance
> variable (using {< >}), and use a copy of that instance variable
> in the method add_fresh_object.
>
> class parent = object (self : 'self)
> val mutable fresh = None
> val mutable children : 'self list = []
> method add_fresh_object =
> let Some x = fresh in children <- Oo.copy x :: children
> initializer fresh <- Some {< >}
> end;;
>
> Anyway, you have apparently found your own solution.
Ah! Yes! I hardly ever use initializers so this idea didn't come to me!
I will try to rewrite my solution and see how this fits into it...
By the way: the example should probably be rewritten as:
class parent = object (self : 'self)
val mutable fresh = None
val mutable children : 'self list = []
method private make_fresh = fresh <- Some {< >}
method add_fresh_object =
let Some x = fresh in
let new_object = Oo.copy x in
new_object#make_fresh; children <- new_object :: children
initializer self#make_fresh
end
This makes sure that the children, too, are able to add fresh objects
to their children list (i.e. the grandchildren).
Thanks for your hint!
Best regards,
Markus Mottl
--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
prev parent reply other threads:[~1999-04-12 17:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-09 22:56 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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199904121210.OAA08612@miss.wu-wien.ac.at \
--to=mottl@miss.wu-wien.ac.at \
--cc=Didier.Remy@inria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox