Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Didier Remy <remy@pacherenc.inria.fr>,
	David Chemouil <David.Chemouil@enseeiht.fr>
Cc: caml-list@inria.fr
Subject: Re: typing of a class
Date: Fri, 10 Mar 2000 09:33:24 +0100	[thread overview]
Message-ID: <20000310093324.41034@pauillac.inria.fr> (raw)
In-Reply-To: <m38bt4n3n7u.fsf@pacherenc.inria.fr>; from Didier Remy on Thu, Mar 09, 2000 at 09:25:25PM +0100

David Chemouil writes:
> > # class a (arg : a -> b) = object(self)
> >     val ob = arg self
> >   end
> >   and b = object
> >   end;;
> > The instance variable self
> > cannot be accessed from the definition of another instance variable
> > I don't understand why it is forbidden for an object to pass itself to
> > another one
> >  (which is possible in Java or Eiffel for example). 

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



  reply	other threads:[~2000-03-10 18:45 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 [this message]
2000-03-16 13:34     ` thierry BRAVIER

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=20000310093324.41034@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=David.Chemouil@enseeiht.fr \
    --cc=caml-list@inria.fr \
    --cc=remy@pacherenc.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