Hugs and Mac and GUI
Tue, 14 Nov 2000 14:35:26 -0700
Hans Aberg writes:
> I tweaked the Hugs sources so that it is always responsive to AppleEvent's:
> When an AppleEvent is receive a Hugs primitive is called, and one has
> primitives to send AppleEvent's. The conversion goes over Hugs strings via
> the AEGizmo's package, plus some extensions I wrote using Flex/Bison. (Some
> AppleEvent's are hardwired and not sent to the Haskell interpreter, though.)
> This is why I want a thread-safe Hugs version, because if Hugs is up and
> running while receiving an event, it may break.
> On the other hand, even though experimental, this variation is the
> interesting one for everyone wanting to explore the limits of functional
> programming and events. :-)
The way we've dealt with Windows and X11 events elsewhere is that events are
placed ina queue which Haskell code can read out of. For example, in my
graphics library, events like mouse movement and key strokes are put into a
channel (a threadsafe queue) for the window that receives the queue. One tends
to run one thread per window whose job is to deal with incoming events -
possibly by forking off another thread to deal with the problem.
Of course, we're limited a bit by the fact that Hugs only has cooperative
multitasking but that works pretty well since most GUI's only deal with one
event at a time anyway - the multi-threading is just a programming convenience.
(Note that I'm not saying "all GUI's" - some would definitely benefit from