[GUI] Another RFC on setting and getting.

Axel Simon A.Simon@ukc.ac.uk
Fri, 4 Apr 2003 19:35:33 +0100


Hi all,

it seems that there are a lot of issues left open about the following 
basic concepts:

- The usage of (:=) and existential types instead of (=:) for turning 
attributes into something which can go into an argument list. Pro for := : 
It reflects the semantics of assigning something to an attribute. Contra 
for := : it might be a keyword in future Haskell, it requires non-Haskell 
98 features.

- The necessity of read only attributes.

- The necessity of write only attributes. Or getting rid of them in favour
of mandatory arguments (to the constructor).

- Callbacks get separate functions which called on<WidgetName><ActionName>

I would like propose the following basic setup, together with the 
questions how read only attribute can fit in. Write only attributes could 
be easily added by just supplying "pushButtonNow :: Setter Button", albeit 
breaking the := syntax - you'd have to say
set b ["Hello" =: label, pushButtonNow]

Here it is:

-- An attribute is a property of a widget. It knows how to set the
-- and how to read the value of this property.
data WidgetClass w => Attr a w = <abstract>

-- The assignment operator joins an attribute with its value.
(=:) :: a -> Attr a w -> Setter w

-- Set and get can be used on every widget.
set :: WidgetClass w => w -> [Setter w] -> IO ()
get :: WidgetClass w => w -> Attr a w -> IO a

-- An example for a Button widget: The constructor has one
-- mandatory argument.
newButton :: Container -> [Setter Button] -> IO Button

-- The Button has at least this attribute.
label :: Attr String Button

-- This is one callback the Button provides. Note that you cannot
-- attach any function at construction time or with the set
-- function. The returned action is the unregister function.
onClicked :: ButtonClass b => b -> IO () -> IO (IO ())


Axel.