grapefruit-examples- Examples using the Grapefruit library

Safe HaskellSafe-Infered



A Grapefruit example which demonstrates switching.

The application creates two counters. These can be incremented with the buttons “Inc 1” and “Inc 2”. On the very right of the window, you always see the current value of one of those counters. Initially, this is counter 1 but you can switch between both counters using the buttons “Switch to 1” and “Switch to 2”.

At the start of the application and at each press on one of the “Switch to” buttons, a further counter is created. The value of the last of these counters is shown left to the other counter value. The initially created counter can be incremented by pushing the button “Inc 1” and each counter created by a press on “Switch to n” can be incremented by pushing the button “Inc n”.

The implementation uses Grapefruit’s switch function which provides switching between signal functions. The arguments of the resulting signal functions are automatically aged, that is, everything before the time they are used is cut off. The right counter value is created by counting the presses of the “Inc” buttons, aging the resulting signals and switching between the aged signals. The left counter value is produced by aging the “Inc” button press signals, counting the occurences in the aged signals and switching between the resulting counter signals.



mainCircuit :: BasicUIBackend uiBackend => UICircuit Window uiBackend era () (DSignal era ())Source

The circuit describing the whole application.