Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Didier Remy <remy@pacherenc.inria.fr>
To: David Chemouil <David.Chemouil@enseeiht.fr>
Cc: caml-list@inria.fr
Subject: Re: typing of a class
Date: 09 Mar 2000 21:25:25 +0100	[thread overview]
Message-ID: <m38bt4n3n7u.fsf@pacherenc.inria.fr> (raw)
In-Reply-To: David Chemouil's message of Tue, 07 Mar 2000 14:12:54 +0100

David Chemouil <David.Chemouil@enseeiht.fr> 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

Indeed, this is unsafe, since the function arg could well try to access 
the field "ob" of self that you are currently trying to initialize (so this
is not done yet).

Consider, for instance, 

    class a = object (self) val ob = self#bad method bad = ob + 1 end;;

which is very similar to:

    type a = { ob : int; }
    let rec self = { ob = self.ob + 1; };;

>  (which is possible in Java or Eiffel for example). 

Yes, but unfortunately Java is not a reference. In particular, it
initializes all fields to meaningless default values (which will often
result in a dynamically-raised null-pointer exception).

        Didier



  parent reply	other threads:[~2000-03-10  8:08 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 [this message]
2000-03-10  8:33   ` Xavier Leroy
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=m38bt4n3n7u.fsf@pacherenc.inria.fr \
    --to=remy@pacherenc.inria.fr \
    --cc=David.Chemouil@enseeiht.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