caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Polymorphic class types?
@ 2005-10-21 20:44 Matt Gushee
  2005-10-22  1:51 ` [Caml-list] " skaller
  2005-10-22  1:59 ` Jacques Garrigue
  0 siblings, 2 replies; 5+ messages in thread
From: Matt Gushee @ 2005-10-21 20:44 UTC (permalink / raw)
  To: caml-list

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



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

end of thread, other threads:[~2005-10-22  8:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-21 20:44 Polymorphic class types? Matt Gushee
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

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