caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* mutually dependent class and type
@ 2008-09-25 22:24 Sébastien Hinderer
  2008-09-25 23:41 ` [Caml-list] " Martin Jambon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sébastien Hinderer @ 2008-09-25 22:24 UTC (permalink / raw)
  To: caml-list

Dear list,

Is there a (clean) way to define simultaneously a class and a type that
are mutually recursive ?
Something like this :
class element (c : content) =
object
  ...
end and type content =
  | Data of string
  | Elements of element list;;

This is of course not a valid OCaml definition, but is there a way to
express it ?

Many thanks in advance for your help,
Sébastien.


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: mutually dependent class and type
@ 2008-09-26  0:03 Jeff Shaw
  2008-09-26  0:08 ` Jeff Shaw
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Shaw @ 2008-09-26  0:03 UTC (permalink / raw)
  To: caml-list

I don't know how you might directly get what you want, but here's one 
way to get an equivalent result.

class element_aux (c : [`Data of string | `Element of element list]) = 
object end

type content = Data of string | Element of element list;;

let content_of_variant = function Data d -> `Data d | Element e -> 
`Element e

class element (c : content) = element_aux (content_of_variant c)


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

end of thread, other threads:[~2008-10-05 13:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-25 22:24 mutually dependent class and type Sébastien Hinderer
2008-09-25 23:41 ` [Caml-list] " Martin Jambon
2008-09-26  6:40 ` Tim Rentsch
2008-10-05 13:31 ` Yann Régis-Gianas
2008-09-26  0:03 Jeff Shaw
2008-09-26  0:08 ` Jeff Shaw

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