Difference between revisions of "Grapefruit"

From HaskellWiki
Jump to navigation Jump to search
m (Added categories)
(→‎Publications and talks: inserted info about “Generic Record Combinators with Static Type Checking”)
Line 104: Line 104:
The following publications and talks are related to Grapefruit:
The following publications and talks are related to Grapefruit:
* Wolfgang Jeltsch: Generic Record Combinators with Static Type Checking. [http://www.risc.jku.at/conferences/ppdp2010/ 12th International Symposium on Principles and Practice of Declarative Programming]. July 26–28, 2010.
** [http://www.informatik.tu-cottbus.de/~jeltsch/research/ppdp-2010-paper.pdf paper]
** [http://www.informatik.tu-cottbus.de/~jeltsch/research/ppdp-2010-slides.pdf slides] (including non-shown additional material)
* Wolfgang Jeltsch: A Generic Foundation for Record Combinators. [http://blogs.shu.edu/projects/IFL2009/ 21st International Symposium on Implementation and Application of Functional Languages]. September 23–25, 2009.
* Wolfgang Jeltsch: A Generic Foundation for Record Combinators. [http://blogs.shu.edu/projects/IFL2009/ 21st International Symposium on Implementation and Application of Functional Languages]. September 23–25, 2009.
** [http://www.informatik.tu-cottbus.de/~jeltsch/research/ifl-2009-slides.pdf slides] (including non-shown additional material)
** [http://www.informatik.tu-cottbus.de/~jeltsch/research/ifl-2009-slides.pdf slides] (including non-shown additional material)

Revision as of 18:25, 5 June 2011


Grapefruit is a library for Functional Reactive Programming (FRP) with a focus on user interfaces. FRP makes it possible to implement reactive and interactive systems in a declarative style. With Grapefruit, user interfaces are described as networks of communicating widgets and windows. Communication is done via different kinds of signals which describe temporal behavior.


Grapefruit has the following important features:

  • a push-based FRP implementation where signals
    • can be memoized using ordinary variable bindings
    • can be merged without doubling of simultaneous events
    • cannot behave differently by starting them at different times
  • a record system which makes it possible that
    • input signals can be left out to get default behavior
    • output signals can be left out to ignore uninteresting data
    • output signals can be chosen and fetched by pattern matching
  • an abstract UI implementation which can work with different backends which in turn use different toolkits to provide different look and feel with one and the same application code (At the moment, the only supported UI toolkit is GTK+ (via Gtk2Hs). We plan to support Qt in the future, making use of the HQK project’s output.)

You might be interested in a comparison of Grapefruit to other FRP libaries


There is a first official Grapefruit release which is release

Grapefruit underwent fundamental interface and implementation changes before this release. A version from before these changes is available as the “classic” version. In contrast to the released version, the classic version contains support for animated graphics and a restricted form of dynamic user interfaces (user interfaces whose widget structure may change). These features are expected to come back in future releases.


First, a note for GHC 6.8 users. If you get warnings of the form “Can’t find interface-file declaration for type constructor or class …” when compiling with GHC 6.8 then don’t panic. This seems to be because of a bug in the (non-official) type family support of GHC 6.8. However, it seems to be harmless.

Released version

You need at least GHC 6.8.3 and Gtk2Hs 0.9.13 to build and use Grapefruit. GHC 6.8.2 can not be used because of GHC bug #1981. Grapefruit was tested with GHC 6.8.3 and Gtk2Hs 0.9.13 as well as with GHC 6.10.1 and a Gtk2Hs 0.10.0.

Grapefruit is released on Hackage. If you do not have special requirements, you can install Grapefruit and its prerequisites as follows:

  1. Install GHC 6.10.1 (see [1]).
  2. Install cabal-install (see [2]).
  3. Insert the line documentation: True into the cabal-install configuration file ($HOME/.cabal/config on UNIX-like systems, %APPDATA%\cabal\config on Windows).
  4. Install Gtk2Hs 0.10.0 (see [3]).
  5. Install Grapefruit by entering cabal update, followed by cabal install grapefruit-ui-gtk grapefruit-examples on a command line.

Current development version

The current development version can be fetched from the darcs repository at http://code.haskell.org/grapefruit/main/. You can build it by building the individual Cabal packages in the grapefruit-* directories. Note that grapefruit-graphics is currently defunct.

Classic version

If you want to try out the classic version, please get it from the darcs repository at http://code.haskell.org/grapefruit/classic/. You can build it by building the individual Cabal packages in the grapefruit-* directories. Alternatively, you can use the Setup.lhs script in the root directory to easily build all packages. You can run the following:

runghc Setup.lhs clean
cleans all packages
runghc Setup.lhs up-to-install configure-options -- build-options -- install-options
configures, builds and installs all packages
runghc Setup.lhs up-to-register configure-options -- build-options -- register-options
configures and builds all packages and registers all library packages (which are all except grapefruit-examples)

The classic version does not work with GHC 6.10.1 and the global Setup.lhs script does not work with newer Cabals.

Running the examples

Released version and current development version

You can run the examples by typing the following lines into GHCi:

:m + Graphics.UI.Grapefruit.Circuit
:m + Graphics.UI.Grapefruit.UIBackend
:m + Examples.Grapefruit.Example
run UIBackend mainCircuit ()

Replace Example with the name of the example to run and UIBackend with the name of the UI backend you want to use. At the moment, the only meaningful replacement for UIBackend is GTK and the only meaningful replacements for Example are Simple and Switching.

We do not provide ready-to-use executables since it is possible (at least in theory) to run the examples with different UI backends and an executable would be fixed to a specific backend.

Classic version

The package grapefruit-examples provides an executable for each example.


Released version

For the following packages, complete documentation is available on Hackage:

For grapefruit-ui-gtk, only the overview page is available. The reason is that Hackage cannot build grapefruit-ui-gtk since Gtk2Hs is not installed on Hackage. However, if you have installed Grapefruit as described above, you have the documentation locally installed (under $HOME/.cabal/share/doc/ under UNIX-like systems).

Current development version

You can build the documentation by issuing runghc Setup.lhs haddock inside the Grapefruit package directories.

Classic version

There is only little documentation of the classic version and there are no plans to change this situation. So you will have to live with what is there. If you have questions, you may always ask the author of Grapefruit as listed in the *.cabal files.

To build the documentation, issue runghc Setup.lhs haddock inside the Grapefruit package directories.

Publications and talks

The following publications and talks are related to Grapefruit:


Grapefruit has a mailing list and a project management website where you can report bugs, for example.


Below are some screenshots from the examples of the classic version. The Simple example is also available in the released version, along with several other examples not mentioned here.

Clicking on the button adds a star to the caption of the button. This doesn’t look very meaningful. However, Simple is actually a very important example since it demonstrates that feedbacks work—the output of the button is transformed and then used as the button’s input.
This is a Mastermind™-like game. The Add button is enabled if and only if the input field contains a valid code and the display box is enabled if and only if the list of guesses does not contain the code chosen by the computer. These properties are described in a declarative way in the source code.
This example demonstrates Grapefruit’s support for animations.