From: Matt Gushee <matt@gushee.net>
To: caml-list@inria.fr
Subject: Polymorphic class types?
Date: Fri, 21 Oct 2005 14:44:58 -0600 [thread overview]
Message-ID: <4359534A.7080706@gushee.net> (raw)
Hello, all--
I am trying to design a high-level GUI library in object-oriented OCaml.
It will be based on LablTk, but that's not really relevant--right now
I'm just trying to work out skeleton classes; the current code doesn't
even import LablTk yet.
Anyway, the concept I'm trying to implement is a notecard metaphor,
where the user will interact with information through a number of cards,
which can be iconified, deiconified, moved around, etc[*]. Cards should
also be able to display arbitrary data types--in practice I think the
data will mostly be key-value structures where the values are mostly
strings, but I don't want to limit it to that.
So you are probably starting to get a sense of the problem: I need a
basic framework of display logic that is independent of the application
data, for positioning cards on the canvas, handling events, etc. But I
also need to be able to get and set the content of cards in response to
GUI events--the content being some arbitrary data structure, as
mentioned above.
So I have been trying to work with parameterized class type like this:
class type ['a] card = object
method id : string
method place : int -> int -> unit
method show : ?expanded:bool -> unit -> unit
method hide : unit -> unit
method expand : unit -> unit
method collapse : int -> int -> unit
method content : (string * 'a) list
method title : string
end
class type ['a] cp_canvas = object
method base : Widget.canvas Widget.widget
method cards : 'a card list
method get_card : string -> 'a card
method add_card : 'a card -> unit
method show : selection -> unit
method hide : selection -> unit
method expand : selection -> unit
method collapse : selection -> unit
end
But I don't think it's going to work. The sticking point is that there
need to be various subtypes of cards, each with appropriate display
logic for its content type, yet the canvas needs to be able to manage
cards in a generic manner--i.e. it needs to work with the 'card'
type--but of course that type doesn't exist, because 'card' takes a
parameter, right?
I won't go into detail here about the problems I've been having--I
suspect the design is wrong, but I have no clear idea of how to do it
right. I know my library could use an abstract 'data' type, which could
then be implemented in an application as, for example,
type data =
| I of int
| F of float
| S of string
...
... but I'd rather not if it can be helped. And I don't care very much
if it's object-oriented ... I started this several months ago and put it
aside for a while, so I don't remember what exactly I was thinking, but
probably the main point of using objects was to make it easy to add new
card types.
So, I would appreciate suggestions.
[*] Am I reinventing HyperCard? Could be ...
--
Matt Gushee
Englewood, CO, USA
next reply other threads:[~2005-10-21 20:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-21 20:44 Matt Gushee [this message]
2005-10-22 1:51 ` [Caml-list] " skaller
2005-10-22 5:53 ` Matt Gushee
2005-10-22 8:52 ` skaller
2005-10-22 1:59 ` Jacques Garrigue
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=4359534A.7080706@gushee.net \
--to=matt@gushee.net \
--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