English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Possibility of Nested Classes and Nested Inheritance?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-12-16 (21:50)
From: John Prevost <j.prevost@g...>
Subject: Re: [Caml-list] Possibility of Nested Classes and Nested Inheritance?
On Thu, 16 Dec 2004 15:59:07 +0100, Jørgen Hermanrud Fjeld <jhf@hex.no> wrote:
> It seems to me that inner classes can always be written as
> parametric classes, which means that OCaml could easily support
> inner classes.  Is this correct? Are there other intrinsic
> reasons why OCaml does not have inner classes, except of course
> that it would take an effort to implement, which I understand.

One typical feature of inner classes that you will never see in O'Caml
is access to the private state of the surrounding class.  On the other

class a (xa : int) =
      val mutable xb = xa
      method get_x = xb
      method set_x x = xb <- x
      method new_b () = object
        method get_x = xb
        method set_x x = xb <- x

Here you see that you can create an object in which the fields of the
containing object are in scope.  But this inner object is not a class,
so it cannot be inherited from.

Anyway, I will look at the rest of your email and look up the papers
your mention some time later.