Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Recursive class/class type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] Recursive class/class type
From: (Christian Szegedy)

> I realiyed that I sometimes need not only recursive
> classes but also mixed recursive types and interfaces.
> Something like this:
> class type a_t =
>    object
>       method f  : a
>    end
> and a =
>     object(self)
>          method f = self
>          method g (x:a_t) = x#f
>     end
> The current Ocaml implementation does not allows this.
> Are there plans to allow types and class types in the same
> recursive declaration block?

Not really, while this might be possible.
That is, mixing class types with classes, not either of them with
ordinary types, as ordinary type definitions have different aliasing

One way to avoid this restriction is to replace a_t by a virtual

class virtual a_t =
      method virtual f  : a
and a =
         method f = self
         method g (x:a_t) = x#f

This defines the same class type a_t.
This also generates some code for a_t, which is not needed, but the
amount of code is very small: 2 closures and 2 function calls.

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: