[GUI] Common GUI API : What would the code look like?

Glynn Clements glynn.clements@virgin.net
Fri, 7 Mar 2003 06:52:11 +0000


David Sankel wrote:

> Ahh, I thought you wanted to create widgets based on
> the String parameter.

No; that wasn't the intention. Although Windows *does* refer to window
classes by name; I'm not sure if that's relevant here, though.

> So in the following code, you would get an ambiguity
> error, right?
> 
> do
>   -- mainWindow defined above
>   a <- create "Some_Button" mainWindow [ label := "Okay" ]
>   runGUI mainWindow -- or whatever it is.

Yes.

> The system does not know if a is a button, a label, or
> whatever.  It would have to look like this to remove
> the ambiguity

With a type-class approach, the type would need to be explicitly
specified somewhere most of the time; it may be that you specify the
variable's type, or you store the handle in a record field which has a
defined type.

Occasionally you might pass the handle to a function which only
operates upon a certain type of widget, in which case the compiler
could infer the type.

> do
>   -- mainWindow defined above
>   a <- create "Some_Button" mainWindow [ label :=
> "Okay" ] :: Button
>   runGUI mainWindow -- or whatever it is.
> 
> It seems like this would defeat the purpose of having
> a generic create function since Button needs to be in
> there somewhere.  Although, I do find your argument
> very credible.

Different types of widget seem to have enough in common that type
classes might be an appropriate solution. Other factors might
contradict this, though.

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