Difference between revisions of "Grapefruit"

From HaskellWiki
Jump to navigation Jump to search
(→‎Running the examples: modernization)
Line 46: Line 46:
   
 
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.
 
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.
 
== Documentation ==
 
 
=== Released version ===
 
 
For the following packages, complete documentation is available on [[Hackage]]:
 
* {{HackagePackage|id=grapefruit-frp}}
 
* {{HackagePackage|id=grapefruit-records}}
 
* {{HackagePackage|id=grapefruit-ui}}
 
* {{HackagePackage|id=grapefruit-examples}}
 
 
For {{HackagePackage|id=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 <code>runghc Setup.lhs haddock</code> 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 <code>runghc Setup.lhs haddock</code> inside the Grapefruit package directories.
 
   
 
== Publications and talks ==
 
== Publications and talks ==

Revision as of 10:04, 11 November 2011


About

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.

Features

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

Installation

Released versions

Grapefruit is released on Hackage. If you do not have special requirements, you can install Grapefruit by saying cabal install grapefruit-ui-gtk grapefruit-examples.

If you do not have installed the gtk package yet, this command will also try to install this package. However, this will fail unless gtk2hs-buildtools is already installed. See the Gtk2Hs website for further information.

Development versions

Development versions can be fetched from the darcs repository at http://darcs.grapefruit-project.org/main. You can build them by building the individual Cabal packages in the grapefruit-* directories. Note that grapefruit-graphics is currently defunct.

Running the examples

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

import Graphics.UI.Grapefruit.Circuit
import Graphics.UI.Grapefruit.UIBackend
import 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. Possible replacements for Example are Converter, ListView, SetView, 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.

Publications and talks

The following publications and talks are related to Grapefruit:

Community

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

Screenshots

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.

Simple
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.
Grapefruit-screenshot-Simple.png
Codebreaker
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.
Grapefruit-screenshot-Codebreaker.png
CircuitingObjects
This example demonstrates Grapefruit’s support for animations.
Grapefruit-screenshot-CircuitingObjects.png