Usage of the GTK+ Binding for Haskell

How to Compile Gtk+HS Applications

The installation of Gtk+HS includes a configuration oracle whose name is gtkhs-config. It is usually located in a binaries directory, such as /usr/local/bin/ (the prefix depends on the location into which the whole library has been installed). The configuration oracle provides version information and the compiler options needed to compile and link programs that import Gtk+HS. Given such a program in a single module `Main.hs', we can compile and link as follows (where $HC represents the executable of the Haskell compiler):

$HC -o prgm `gtkhs-config --cflags --libs` Main.hs

Usually, however, when compilation and linking is separate, the output of

gtkhs-config --cflags

determines the compile flags, whereas

gtkhs-config --libs

gives the link flags. The configuration oracle understands the following flags:

--version pint the version of the current installation
--cflags print the compile flags
--libs print the link flags
--prefix print the installation prefix

If support for gtkglarea and/or iHaskell is needed, the arguments gtkglarea and iH, respectively, need to be passed to gtkhs-config. Moreover, the Gtk+HS installation needs to have been compiled including support for these two features. If gtkhs-config is invoked without any argument, it lists all features supported by the present installation.

An Example Application: The Boolean Editor

The Boolean Editor (in the module BoolEd) illustrates the use of Gtk+HS for GUI programming in Haskell. It is an application that supports the editing of Boolean files - i.e., files that contain either False or True. While not terribly useful as an application, the implementation of the Boolean Editor illustrates the use of the GTK+ toolkit from Haskell and the implementation of important concepts, such as maintaining global state in the application and the synchronisation of multiple windows. In particular, note how the Boolean Editor changes the contents of windows that edit the same file in sync.

The use of the Boolean Editor as an example application is due to Havoc Pennington.


This page is part of Manuel Chakravarty's WWW-stuff.

Last modified: Tue Sep 11 00:53:26 EST 2001