[GUI] Common GUI API : What would the code look like?
Wed, 5 Mar 2003 10:35:39 +0000
David Sankel wrote:
> Questions ::
> 1) How does the interface look in Test_midlevel.hs?
> Is there any critiques in
> regard to using this style in CGA (Common GUI API)?
1. Widgets aren't being given names. This makes it impossible to refer
to them from outside of the code. It also eliminates the possibility
of implementing a useable Xt (e.g. Motif) backend. Toolkits which
don't name widgets can just ignore the name.
2. Widget properties (label, position, dimension) are being embedded
in the code, which is a bad idea. This point is closely tied in with
3. Personally, I would prefer a generic widget creation function,
rather than a different function for each type of widget. E.g. Xt has
XtCreateWidget(), with the widget class being passed as an argument.
A more Haskell-ish approach would be to use typeclasses, e.g.:
class Widget a where
create :: String -> a -> [Property] -> IO a
-- create name parent properties = ...
Of course, you can always provide type-specific constructors in
addition; doing the reverse is more involved.
Glynn Clements <firstname.lastname@example.org>