[
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: | Matt Gushee <mgushee@h...> |
| Subject: | Re: [Caml-list] Type problem... possible design problem |
chris.danx wrote:
> type childNode = LeafNode of sgLeaf | IntNode of sgInternal
> and
> class sgLeaf
.... etc. ...
> 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?
This seems to me like a good case for class types. How about something like:
class type leafType =
object
method draw : unit -> unit
end
class type ['a] internalType =
object
method addChild : 'a -> unit
method getChildren : unit -> 'a list
method draw : unit -> unit
end
type childNode =
LeafNode of leafType
| IntNode of childNode internalType
Then, of course, you'll need to define concrete classes that fit the
class type signatures and/or coerce objects to those types.
I'm not sure this is the most elegant solution, but it is at least
syntactically valid, and seems to do what you want.
--
Matt Gushee
Englewood, CO, USA