[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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: szegedy@t-online.de (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
semantics.
One way to avoid this restriction is to replace a_t by a virtual
class.
class virtual a_t =
object
method virtual f : a
end
and a =
object(self)
method f = self
method g (x:a_t) = x#f
end
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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners