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
Recursive class+type definitions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-07-16 (09:01)
From: Jacques GARRIGUE <garrigue@m...>
Subject: Re: [Caml-list] Recursive class+type definitions
From: "Chris King" <>

> You can get the exact behavior you want using a pair of recursive
> modules (see the "Language Extensions" section of the manual), one for
> each of mypoint and mypointlist, but it's a lot more verbose (since
> recursive modules require you to explicity give their signatures).

I would think that one recursive module is sufficient.
Note also that, as this virtual class has no concrete methods, it
could just be defined as a class type (just means you can only use it
in interfaces and type annotations.) Then there is no code

module rec Mypoint : sig
  class type p =
       method getx : float
       method getlist : Mypoint.plist
  type plist = Empty | Cons of (p * Mypoint.plist)
end = Mypoint

Jacques Garrigue