caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Type problem... possible design problem
@ 2004-12-18  0:42 chris.danx
  2004-12-18  4:00 ` [Caml-list] " Matt Gushee
  2004-12-18  8:07 ` Jon Harrop
  0 siblings, 2 replies; 8+ messages in thread
From: chris.danx @ 2004-12-18  0:42 UTC (permalink / raw)
  To: O'Caml Mailing List

Hi,

What is the solution to the following problem?  There are two types of 
object in a scene graph, those that may have children and those may not. 
     A leaf may not have children.

For various reasons, I need to preserve the methods of internal nodes 
(non leaves).  I thought about something like this

type childNode = LeafNode of sgLeaf | IntNode of sgInternal
and
class sgLeaf
   = object(self)

     method draw () = ()

   end
and
class sgInternal
   = object(self)

     method addChild (child : childNode) = ()

     method getChildren () = ...

     method draw () = ()
   end

but this isn't legal O'Caml.  The following also doesn't work.

type childNode =
     LeafNode of <draw:unit -> unit; ..>
   | IntNode  of <draw:unit -> unit; addChild: childNode -> unit; ..>


I've not programmed in O'Caml for a while and am not yet fully 
comfortable with ocamls object system anyway, so I may be being silly. 
Can anyone shed some light on a solution to this?

Basically I need to be able to call addChild, etc for internal nodes if 
they're not leaves so I need to remember whether the type contains only 
draw or it also contains addChild, etc.  It will be clients that call 
operations like addChild, getChildren, ...

Perhaps this is the wrong solution entirely.

Thanks,
Chris


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

end of thread, other threads:[~2004-12-20 11:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-18  0:42 Type problem... possible design problem chris.danx
2004-12-18  4:00 ` [Caml-list] " Matt Gushee
2004-12-18  8:07 ` Jon Harrop
2004-12-18 14:28   ` chris.danx
2004-12-18 15:27     ` Richard Jones
2004-12-18 20:06       ` chris.danx
2004-12-18 18:37     ` Jon Harrop
2004-12-20 11:50     ` skaller

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