next up previous contents
Next: A First Example Up: Getting Started Previous: Getting Started

Basics

When we design and implement a graphical user interface, we have to take two aspects into account: the static aspect, which specifies its appearance (which buttons to place where, what menus to display, etc.), and the dynamic aspect, which specifies its behaviour in reaction to the user's actions. The two can be interlinked: as a reaction to the user's action, the graphical user interface may change its appearance.

In HTK, these two aspects are modelled by monads. The static aspect is modelled in the IO monad, where all of Haskell's external interactions takes place. The dynamic aspect is modelled by events. For a more complete description of events, we refer to [6], but for the time being, events are an abstract datatype with three main operations:

Events form a monad, with monad composition given by >>>= and always. The monad composition corresponds to event sequencing; if we synchronise on an event composed from simple events, we wait for each of them in turn. By composing events in this way, fairly complex behaviours can be modelled in a single event.

That the dynamic behaviour is not modelled with IO actions directly reflects the fact that user interaction in a graphical user interface is different from other forms of I/O, because it happens asynchronously.

Further, events allow the user interface to be concurrent in a natural and controlled way, leading to a reasonable and still tractable degree of concurrency; the function

spawnEvent :: Event () -> IO (IO ())
spawns a concurrent thread which syncronises on the given event. The IO action returned kills the concurrent thread.


next up previous contents
Next: A First Example Up: Getting Started Previous: Getting Started

Christoph Lueth
Wed May 29 13:20:38 MEST 2002