Difference between revisions of "Grapefruit"

From HaskellWiki
Jump to navigation Jump to search
(removal of paragraph about error messages during building (don’t occur with the current version anymore))
(→‎Development versions: adapted info to changes in darcs repositories related to the start of Grapefruit 0.2)
(55 intermediate revisions by 6 users not shown)
Line 2: Line 2:
 
[[Category:Libraries]]
 
[[Category:Libraries]]
 
[[Category:Arrow]]
 
[[Category:Arrow]]
  +
[[Category:Graphics]]
  +
[[Category:FRP]]
  +
[[Category:Packages]]
   
 
== About ==
 
== About ==
   
Grapefruit is a library for creating graphical user interfaces and animated graphics in a declarative way. It is currently based on [[Gtk2Hs]] but implementations on top of other GUI libraries are planned for the future.
+
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 makes it possible to implement graphical user interfaces by describing them as systems of interconnected components. Components can be visible components like widgets and windows but also invisible components which provide certain control functionality. Component systems can be built from components by using methods from the <hask>Arrow</hask> and <hask>ArrowLoop</hask> classes.
 
   
  +
Grapefruit has the following important features:
Components communicate via signals. A signal is either continuous or discrete. A continuous signal denotes a time-varying value. A discrete signal denotes a sequence of values assigned to discrete points in time and can therefore be used to model streams of events. Several functions allow the construction of signals in a purely functional manner.
 
  +
* 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 [[Grapefruit/Comparison to other FRP libraries|comparison of Grapefruit to other FRP libaries]]
Grapefruit has also support for list signals, special signals denoting time-varying lists where each element has a unique identity. An algebra for list signals provides operations like concatenation, filtering and sorting. The key point is that when the value of a list signal changes, the values of the list signals depending on it do not have to be recalculated completely but can be just updated incrementally.
 
   
  +
== Installation ==
User interfaces with a changing collection of widgets are also possible with Grapefruit. There is a special widget which takes a list signal of widgets as its input and always contains the elements of it as its child widgets.
 
   
  +
=== Released versions ===
Furthermore, it is possible to implement animations using graphic signals. These are implemented on top of OpenGL. So-called caching graphic signals are available to make use of OpenGL’s display lists.
 
   
  +
Grapefruit is released on [[Hackage]]. If you do not have special requirements, you can install Grapefruit by saying <code>cabal install grapefruit-ui-gtk grapefruit-examples</code>.
With Grapefruit, user interface descriptions always cover the complete lifetime of the respective interface. No explicit event handler registrations and no explicit recalculations of values are necessary. This is in line with the declarative nature of Haskell because it stresses how the user interface operates instead of how this operation is achieved. Internally though, signals are implemented efficiently using the event dispatching and handling mechanism of the underlying GUI toolkit.
 
   
  +
If you do not have installed the <code>gtk</code> package yet, this command will also try to install this package. However, this will fail unless <code>gtk2hs-buildtools</code> is already installed. See the [http://projects.haskell.org/gtk2hs/ Gtk2Hs website] for further information.
The roots of Grapefruit lie in systems like [[Applications_and_libraries/GUI_libraries#FranTk|FranTk]] and [[Applications_and_libraries/GUI_libraries#wxFruit|wxFruit]]. Grapefruit tries to combine concepts of these systems with new ideas to become a system which maintains a reasonable balance between ease of use and efficiency, and is applicable to real world problems.
 
   
== Status ==
+
=== Development versions ===
   
  +
Currently, Grapefruit is undergoing a complete rewrite, which will base it on new concepts. For each part of the new Grapefruit, there is a corresponding [[Darcs|darcs]] repository at <nowiki>http://darcs.grapefruit-project.org/</nowiki>''package-name''/main. The code of the old 0.1&nbsp;branch of Grapefruit resides in a single darcs repository at http://darcs.grapefruit-project.org/monolithic/0.1.
As of Oktober&nbsp;2007, Grapefruit is still in an early stage. Lots of basic concepts are implemented but Grapefruit still lacks a wide variety of widgets, for example. However, adding new widgets shouldn’t be too difficult since Grapefruit provides good generic support for doing this.
 
   
  +
== Running the examples ==
Furthermore, work on formal specification and verification of GUI properties based on Grapefruit’s GUI programming interface and [[Dependent type|dependent types]] has just started. The proof assistant [[Coq]] will be used in this context.
 
   
  +
You can run the examples by typing the following lines into GHCi:
== Source code ==
 
   
  +
<blockquote><p><code>import Graphics.UI.Grapefruit.Circuit</code><br /><code>import Graphics.UI.Grapefruit.'''''UIBackend'''''</code><br /><code>import Examples.Grapefruit.'''''Example'''''</code><br /><code>run '''''UIBackend''''' mainCircuit ()</code></p></blockquote>
The source code of Grapefruit resides inside a [[Darcs|darcs]] repository under http://softbase.org/grapefruit/darcs/main/. To get a copy, you can use the command <code><nowiki>darcs get http://softbase.org/grapefruit/darcs/main</nowiki></code>.
 
   
  +
Replace <code>'''''Example'''''</code> with the name of the example to run and <code>'''''UIBackend'''''</code> with the name of the UI backend you want to use. At the moment, the only meaningful replacement for <code>'''''UIBackend'''''</code> is <code>GTK</code>. Possible replacements for <code>'''''Example'''''</code> are <code>Converter</code>, <code>ListView</code>, <code>SetView</code>, <code>Simple</code>, and <code>Switching</code>.
== Building ==
 
   
  +
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.
You need at least GHC&nbsp;6.8.1 and Gtk2Hs&nbsp;0.9.12.1 to build and use Grapefruit. Currently, Grapefruit is tested with GHC&nbsp;6.8.2 and Gtk2Hs&nbsp;0.9.12.1.
 
   
  +
== Publications and talks ==
To actually build Grapefruit, use [http://haskell.org/cabal/ Cabal]. Grapefruit consists of the following packages:
 
* grapefruit-frp
 
* grapefruit-records
 
* grapefruit-gui
 
* grapefruit-graphics
 
* grapefruit-examples
 
You should build these packages in this order by descending into the respective directories and issuing the appropriate Cabal commands there. If you don’t have any special requirements (like a non-default install path), you can use the following sequence of commands for each package:<blockquote><p><code>runghc Setup.lhs configure<br />runghc Setup.lhs build<br />runghc Setup.lhs install</code></p></blockquote>
 
   
  +
See [https://grapefruit-project.org/publications-and-talks the respective list] on [https://grapefruit-project.org/ the new Grapefruit website].
== Documentation ==
 
   
  +
== Community ==
There is also documentation generated by [[Haddock]]. This documentation comes in two flavors. The [http://softbase.org/grapefruit/doc/api/ API documentation] covers only the public interface while the [http://softbase.org/grapefruit/doc/cif/ complete documentation] covers also the internals. Note that the documentation might be out of date since it is not automatically regenerated on every commit yet.
 
   
  +
Grapefruit has a [http://projects.haskell.org/cgi-bin/mailman/listinfo/grapefruit mailing list] and a [http://trac.haskell.org/grapefruit/ project management website] where you can [http://trac.haskell.org/grapefruit/newticket report bugs], for example.
== Grapefruit-related talks ==
 
 
* Wolfgang Jeltsch: Funktionale GUI-Programmierung in Haskell mit Grapefruit. Haskell in Leipzig&nbsp;2. July 10, 2007.
 
** [http://video.google.com/videoplay?docid=-8925440604853415181 video of the talk]
 
** [[Media:Grapefruit_HaL_2_presentation.pdf|presentation used in the talk]]
 
   
 
== Screenshots ==
 
== Screenshots ==
   
  +
Below are some screenshots from the examples of an earlier Grapefruit version. The Simple example is also available in the current version, along with several other examples not mentioned here.
Following are some screenshots from example programs using Grapefruit:
 
 
;Simple
 
;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.
 
: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.

Revision as of 14:47, 10 February 2012


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

Currently, Grapefruit is undergoing a complete rewrite, which will base it on new concepts. For each part of the new Grapefruit, there is a corresponding darcs repository at http://darcs.grapefruit-project.org/package-name/main. The code of the old 0.1 branch of Grapefruit resides in a single darcs repository at http://darcs.grapefruit-project.org/monolithic/0.1.

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

See the respective list on the new Grapefruit website.

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 an earlier Grapefruit version. The Simple example is also available in the current 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