[GUI] GUIs and events/callbacks.

Daan Leijen daanleijen@xs4all.nl
Tue, 11 Mar 2003 09:27:29 +0100


> For example, consider John Meacham's simple example. As G.Russel pointed
> out, (almost) all the event-based implementation suffer from a problem:
> if the user clicks the button twice, fastly, the program does not exit.
>
> This is because the programs are written like
>
> onClick button callback1
>
> callback1 = doSomething >> unregister callback1 >> onClick button
> callback2 = doSomethingElse
>
> The first ">>" in callback1 can be the point on wich the user clicks the
> button for the second time!

Just for the record: this is *not* true for most (all?) event
based implementations as they are *not* concurrent (at least not
pre-emptively concurrent). Somewhere down, there is an event loop --
a loop that waits for an event, executes a callback, and loops again.
Even though more events can happen while executing the callback, it
will only propegate into Haskell once the callback returns and the
event loop pops it off the OS event queue. [note: You can achieve more
concurrency in Haskell by using Haskell threads but even than one
has to wait till the callbacks are done or otherwise the runtime system
sits idle while waiting for the next event (as this is a C call).]

-- Daan