[GUI] Another call for votes

Axel Simon A.Simon@ukc.ac.uk
Wed, 19 Mar 2003 14:46:47 +0000


On Tue, Mar 18, 2003 at 06:46:42PM +0000, Glynn Clements wrote:
> Axel Simon wrote:
> >  I think this is one of the mid-level features we want to keep: A 
> > convenient syntax, not just a bunch of IO functions like
> > 
> > >  buttonOnClick    :: IO () -> Button -> IO ()
> > >  buttonGetOnClick :: Button -> IO (IO ())
> 
> The "convenient syntax" only makes sense if you view events and
> callbacks as being in 1:1 correspondence. Not all toolkits take this
> view. Xt has callback lists, where callbacks can be added and removed
> independently (callbacks are identified by equality on function
> pointers, which becomes problematic if you want to pass Haskell
> functions directly); similarly for the signal/slot approach.
 Gtk uses a very similar approach in that each event can have several 
callbacks registered and you can remove each callback individually. So I 
think my proposal serves this 1:n correspondance. You can say:

remove :: MVar (IO ()) <- newEmptyMVar 

button [label =: "Open Dialogs",
	on click := messageBox "hi there",
        onOff click remove := messageBox "bye there"]

which will attach two callbacks to the same event whereas the remove MVar 
will only get the unregister function for the second callback. If you want 
to remove both at a time you say:

button [label =: "Open Dialogs",
	opeonOff click remove =: messageBox "hi there",
        onOff click remove =: messageBox "bye there"]

and "withMVar remove id" as an IO action will remove both callbacks. Note:

a) fits into syntax
b) 1:n event:callback correspondance
c) the MVar approach is actually convenient in practice (as you need to 
store the unregister function/signal-id somewhere anyway)
d) can be implemented with equality on C function pointers under the hood 
if necessary

No?
Axel.