[GUI] Are windows just ordinary widgets?

Glynn Clements glynn.clements@virgin.net
Mon, 28 Apr 2003 17:59:10 +0100


Wolfgang Thaller wrote:

> Now perhaps we want a common datatype "Widget" with functions
>      toWidget :: Widget w => w -> Widget
> and fromWidget :: Widget w => Widget -> Maybe w
> 
> Perhaps we want a datatype "Pane" (or "Control" or whatever) with
> 	toPane :: Pane p => p -> Pane
> and so on.

I don't see the point in this. If you have classes, then surely you
don't need the types?

> If I had a "Pane" datatype, I wouldn't really need the "Widget" 
> anymore, but of course, one can never know.
> The "Pane" datatype would be the natural place to implement a lot of 
> functionality at least on Mac OS, so if it's there, I'm happy, and I 
> could then implement a Widget datatype as a simple discriminated union 
> datatype. If there was no Pane datatype, the implementation for the 
> widget datatype would become slightly ugly and inelegant on Mac OS...

The obvious solution seems to be to use classes. E.g. operations on
menu bars would operate on the MenuBar class, i.e.

	doSomethingToMenuBar :: MenuBar w => w -> ...

For MacOS, a menu bar would be an instance of MenuBar. For Motif, it
would be an instance of both MenuBar and Widget. Code which is meant
to be portable would only use the MenuBar methods; Motif-specific code
could also use the Widget methods.

It seems to me that, as far as possible, the CGA should define (and
use) classes rather than types.

-- 
Glynn Clements <glynn.clements@virgin.net>