Declarative Programming Of Interactive Systems With Grapefruit
Room: BBL room 471
Speaker: Wolfgang Jeltsch (TU Cottbus)
Title: Declarative Programming of Interactive Systems with Grapefruit
Functional programming languages are famous for supporting a declarative programming style where the
program says what should be done instead how it should be done. However, GUI and graphics libraries
of functional languages are typically imperative in nature. An example is the Haskell GTK+ binding
Gtk2Hs. The programmer has to create widgets and windows explicitely and register event handlers.
In turn, event handlers read the state of widgets and windows and modify the state of other widgets
and windows depending on it.
Functional Reactive Programming (FRP) is a declarative programming model for reactive and
interactive systems. Its key concept is the signal. A signal describes a part of the system’s
behavior for all time. There are continuous signals which can be thought of as functions from times
to values, and discrete signals which describe sequences of values which are related to discrete
times. This can be illustrated with a push button in a GUI. The button’s caption is determined by
a continuous signal of strings while the sequence of all push events is represented by a discrete
signal over the unit type.
This talk presents the Grapefruit library, an implementation of FRP with a focus on GUI and graphics
programming. With Grapefruit, user interfaces are described as systems of interconnected components
which communicate via signals, and animated graphics are represented directly by signals. New
signals can be composed from existing ones in a purely functional way by using a variety of
combinator functions. User interfaces with changing structure are also supported and can also be
Previous Haskell FRP solutions are typically implemented in a pull-based way, meaning that an event
occurence or time step results in the whole system state being recalculated. In contrast,
Grapefruit uses a common notification mechanism based on event handlers internally so that
unnecessary updates are usually avoided. This helps on making Grapefruit easy to use and efficient
at the same time.