[GUI] And a simpler, but less extensible alternative

Nick Name nick.name at inwind.it
Tue Sep 16 15:19:52 EDT 2003


The simpler alternative, wich disables the definition of new modes for 
attributes in other modules, but is also easier to use, is:

-------
data Readable = Readable
data Writeable = Writeable

data Attr m w a = Attr (w -> IO a) (w -> a -> IO ())  

newAttr :: (w -> IO a) -> (w -> a -> IO ()) -> 
   Attr (Readable,Writeable) w a

readAttr :: (w -> IO a) -> Attr (Readable,()) w a

writeAttr :: (w -> a -> IO ()) -> Attr ((),Writeable) w a

get :: w -> Attr (Readable,m) w a -> IO a

(=:) (Attr getter setter) x = newProp (\w -> setter w x) getter setter

...
-------

Also, again by using typeclasses, it can be enforced that modes are in a 
fixed set, for example to avoid that one writes "Attr 
(Writeable,Readable)" in place of "Attr (Readable,Writeable)".

As usual, I have compiled htoolkit with the modifications. This time I 
have not used any non H98 feature, I just have the exact type hierarchy 
of htoolkit but with well-typed read-only and write-only attributes. 
The system can be extended to other switches, like "listenable" or 
"write-once" or similar with a linear number of types, if I am not 
wrong (so this proposition is always true, uh?).

I don't know if it's better to leave around the ReadMode and WriteMode 
typeclasses or to leave things as in this message, wich looks clearer 
also in type declarations (maybe extensible is better, anyways).

Vincenzo



More information about the GUI mailing list