A GTK+ Binding for Haskell

  freshmeat.net entry
FreshPorts entry

GTK+ This project is no longer active. For an alternative see Gtk2Hs. GTK+ (The GIMP Toolkit) is an open source GUI toolkit originally developed for the GIMP (GNU Image Manipulation Program). However, it is used in a range of other projects by now, most notably the GNOME (GNU Network Object Model Environment). GTK+ is portable as it does not rely on X window's Xt library, but instead accesses the underlying window system via a thin API, called GDK. Furthermore, it uses a consequent object-oriented design and realizes callback functionality via a flexible and powerful signal mechanism (not identical with, but oriented by *nix signals). GTK+ object-oriented features are realized in plain C; and it has been designed with an eye on making it not too difficult to interface from high-level languages. Therefore, it is a very interesting choice for a GUI toolkit for Haskell.

For a summary of the latest changes to the CVS head, check out the NEWS in CVS. Here is some more general news:

Currently, the GTK+ binding is available for the Glasgow Haskell Compiler only, but I plan to include support for NHC98.

Current Status

The basic functionality and many advanced widgets are supported. Furthermore, there is some GLib and GDK support as well as full support for GtkGLArea, which allows you to render OpenGL graphics in a GTK+ window. Everything from Chapter 3 of Havoc Pennington's GTK+/Gnome book is implemented (it's a good book, by the way). However, GTK+ provides a number of more sophisticated and/or specialised widgets that aren't supported yet.

The implemented functionality should be sufficient for average user interfaces. You may want to have a look at the screenshot and code of one of the small examples that I used to test the binding. Or a screenshot of the Boolean Editor.

Releases

The following lists source and binary packages of Gtk+HS. Note that the binary packages are compiled for use with GHC and that they will only work with exactly the version of GHC that they have been compiled for. Similarly, the used package of C->Haskell must also be for the same version of GHC.

gtk+hs-0.15.3 [ tar.gz | i386.rpm | src.rpm | i386.deb | FreeBSD port ]
This is a source-only release that requires C->Haskell 0.10.8 upwards.
gtk+hs-0.15.2 [ tar.gz | i386.rpm | src.rpm | i386.deb | FreeBSD port ]
This is a source-only release that requires GHC 4.08 and C->Haskell 0.10.8 upwards.
gtk+hs-0.14.10 [ tar.gz | i386.rpm | src.rpm | i386.deb | FreeBSD port ]
This is the last binary release before development is re-focused towards GTK+ 2.0. This release requires GHC 4.08 and C->Haskell 0.10.8 upwards. The binary packages provided here are for GHC 5.04.1 with C->Haskell 0.10.17. (NB: You need to install the C->Haskell package in any case - even if you do not intend to compile Gtk+HS yourself. This is because Gtk+HS needs the C->Haskell libraries.)
gtk+hs-0.11.5 [ tar.gz | i386.rpm1 | src.rpm | i386-unknown-linux.tar.gz1 ]
To compile it yourself, you need GHC 4.08 and C->Haskell 0.9.9 upwards. The binaries are for GHC 5.00.x with C->Haskell 0.9.9. (NB: You need to install the C->Haskell package in any case - even if you do not intend to compile Gtk+HS yourself. This is because Gtk+HS needs the C->Haskell libraries.)
gtk+hs-0.10.5.tar.gz
To compile it, you need GHC 4.08 and C->Haskell 0.8.2 upwards. This release fixes some more bugs.
gtk+hs-0.10.4.tar.gz
To compile it, you need GHC 4.08 and C->Haskell 0.8.2 upwards. This release fixes bugs and adds an install target.
gtk+hs-0.10.2.tar.gz
To compile it, you need GHC 4.08 and C->Haskell 0.8.2 upwards. This has the menu widgets included (thanks to Axel Krauth's contribution) and all the prefixes dropped from identifiers.
[If you have used earlier versions, beware that the naming conventions have changed. A list of changes is in the NEWS in CVS.]

Mailing List

To subscribe to the Gtk+HS mailing list, visit the subscription page. The address of the list is gtkhs@haskell.org and there is also an online archive.

Anonymous access to the Gnome CVS

For those who prefer the bleeding edge fresh from CVS over tar balls, Gtk+HS can be obtained by anonymous CVS from the Gnome repository. Here is what you have to know:

This creates a directory named gtk+hs wherever you issue the checkout command. When getting the stuff from CVS, don't forget to invoke autoconf before ./configure (the configure script is not pre-generated in the CVS). By virtue of the fabulous LXR tool, you can also browse the source code online.

Documentation

Currently, the only Gtk+HS-specific documentation is a a brief usage guide. There is no dedicated documentation describing the API of GTK+ in Haskell. However, the binding remains as close as possible to the original GTK+ interface (while, at the same time, embedding the functionality nicely in Haskell's type system). Thus, I recommend to consult the original GTK+ documentation in conjunction with the interface specification of the Haskell modules. Wherever, I deviated significantly from GTK+'s original interface, the module header or a comment at the function definition explains the differences.

Check out the GTK+ 1.2 tutorial and the reference manuals for GTK+, GDK, and GLib.

Applications

The following is a (probably incomplete list) of publicly available applications that use Gtk+HS:

There are more applications of which I know that they are using the toolkit, but they haven't been publicly released.

iHaskell

iHaskell is a layer on top of Gtk+Haskell that

  1. provides convenience functions for frequently used programming patterns,
  2. haskellises the GTK+ API, and
  3. eliminates the need for explicit mutable variables (IORef & its evil friends) for the representation of the state space of a GUI.

iHaskell is part of Gtk+HS standard release (in the subdirectory ih/). To enable it, you need to install the Haskell Ports Library first and pass the option --enable-ih to ./configure when compiling Gtk+HS. You can have a direct look at the iHaskell code in CVS, too. The only documentation to date are the slides of a talk that I have given at the Packwood meeting of the IFIP WG 2.8.

Future Development

The next major development will be support for GTK+ 2.0. This will be realised using a recently implemented feature for conditional compilation in C->Haskell. As a result, it will be possible support GTK+ 1.2 and GTK+ 2.0 within one set of Haskell binding sources.

The code is released under the GNU Library General Public Lisence. This basically means that you can do whatever you want with it, as long as you share any improvements to the library with the rest of us. I welcome everybody to contribute bindings for widgets and functions that are not supported yet; I only ask any contributors that they code in accordance with the style and design of the existing modules.


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

Last modified: Fri Jul 15 22:33:02 EST 2005