From: "thierry BRAVIER" <thierry.bravier@dassault-aviation.fr>
To: caml-list@inria.fr
Subject: Re: typing of a class
Date: Thu, 16 Mar 2000 14:34:57 +0100 [thread overview]
Message-ID: <38D0E301.368FB52C@dassault-aviation.fr> (raw)
In-Reply-To: <20000310093324.41034@pauillac.inria.fr>
Dear ocamlers,
Xavier Leroy a écrit:
> You can write your example just like in Java, by 1- making the
> instance variable mutable, and 2- using an option type to play the
> role of Java's null pointers. You'd get:
>
> class a arg = object(self)
> val mutable ob = (None : b option)
> initializer ob <- Some(arg self)
> end;;
>
> It's not pretty, but that's exactly what's going on "under the hood"
> in the equivalent Java code.
>
> - Xavier Leroy
An alternative technique I often use is
let not_ready () = failwith "not ready"
class a arg = object (self)
val mutable ob = not_ready
initializer let it = arg self in ob <- (fun () -> it)
method private ob = ob ()
end
the advantage is that it is not necessary anymore to match ob with Some x;
the drawback is that 'ob' value must now be accessed as 'ob ()'.
A workaround is to introduce method ob and type 'self#ob'.
Of course, field ob must not be accessed during (arg self) computation :-(
Cheers.
prev parent reply other threads:[~2000-03-17 10:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-07 13:12 David Chemouil
2000-03-08 19:00 ` John Prevost
2000-03-09 0:52 ` Benoit Deboursetty
2000-03-09 20:25 ` Didier Remy
2000-03-10 8:33 ` Xavier Leroy
2000-03-16 13:34 ` thierry BRAVIER [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=38D0E301.368FB52C@dassault-aviation.fr \
--to=thierry.bravier@dassault-aviation.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