Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Matt Gushee <mgushee@havenrock.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Type problem... possible design problem
Date: Fri, 17 Dec 2004 21:00:49 -0700	[thread overview]
Message-ID: <41C3AB71.4070107@havenrock.com> (raw)
In-Reply-To: <41C37CF7.5050400@ntlworld.com>

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


  reply	other threads:[~2004-12-18  4:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-18  0:42 chris.danx
2004-12-18  4:00 ` Matt Gushee [this message]
2004-12-18  8:07 ` [Caml-list] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41C3AB71.4070107@havenrock.com \
    --to=mgushee@havenrock.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox