Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
hand:

class a (xa : int) =
    object
      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
      end
    end;;


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.

John.