[GUI] Re: events & callbacks
Daan Leijen
daanleijen@xs4all.nl
Tue, 11 Mar 2003 15:47:13 +0100
On Tue, 11 Mar 2003 13:52:46 +0100, George Russell <ger@tzi.de> wrote:
> Daan wrote (about whether callbacks are concurrent)
>> 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).]
>
> Well, if the callback model requires you to work in a gaol in which
> concurrency is banned, it is useless. I rest my case, m'lud.
It has nothing to do with the Haskell "callback" model. It is how most GUI libraries just work on the OS level: win32, X, GTK, etc.
This doesn't mean you can't do all kinds of tricks to implement a more appropiate model in Haskell -- I just wanted to make clear that
the argument/example/supposed bug was false.
> As far as I'm concerned you can forget about any GUI which doesn't allow
> you to write a function
> confirm :: String -> IO Bool
> which puts up a window containing the String and "OK" and "Cancel" buttons,
> instead making the user put up with the CPS style.
> confirm :: String -> (Bool -> IO ()) -> IO ()
Again, it has nothing to do with Haskell but depends on the OS. Fortunately
all platforms indeed allow you to run a window "modally". (In this case,
you call C world again from a callback, but that C call will go into its
own event loop and call Haskell callbacks from there again.).
In short, the eventloop model is what each platform provides and it is
up to us to implement something nice in Haskell. Since each platform has
"modal" windows, there is no need for CPS style programming. Even better,
using concurrency, I have even found an implementation of "sync" on top
of the eventloop model.
All the best,
Daan.
> instead making the user put up with the CPS style.
> confirm :: String -> (Bool -> IO ()) -> IO ()
>
> _______________________________________________
> GUI mailing list
> GUI@haskell.org
> http://www.haskell.org/mailman/listinfo/gui
>
>