caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Recursive class/class type
@ 2004-07-08 22:56 Christian Szegedy
  2004-07-09  1:13 ` Jacques GARRIGUE
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Szegedy @ 2004-07-08 22:56 UTC (permalink / raw)
  To: caml

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?

-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Recursive class/class type
  2004-07-08 22:56 [Caml-list] Recursive class/class type Christian Szegedy
@ 2004-07-09  1:13 ` Jacques GARRIGUE
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques GARRIGUE @ 2004-07-09  1:13 UTC (permalink / raw)
  To: szegedy; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-07-09  1:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-08 22:56 [Caml-list] Recursive class/class type Christian Szegedy
2004-07-09  1:13 ` Jacques GARRIGUE

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).