The program shows a button and a numeric display. Whenever the button is pressed, the number shown in the display is incremented.
The application specific code in this example sits between the button and the display. It internally maintains a counter which is incremented and output to the display whenever a click is received from the button.
Here is the source code:
module Main(main) where -- A very simple counter import Fudgets main = fudlogue (shellF "Counter" counterF) counterF = intDispF >==< absF countSP >==< buttonF "Increment" countSP = mapAccumlSP inc 0 where inc n _ = (n+1,n+1)
counterF
, in which
the two GUI elements and a stream processor containing the counter
are serially connected. This is best illustrated as a circuit diagram:
As may be apparent, Fudget programs are built hierarchically by combining simple fudgets and stream processors into more complex ones.
A stream
processor can be seen as a process which communicates with the outside
world through an input stream and an output stream. In the Fudget library
a stream processor is represented with the (abstract) type
SP
a b, where a is the type of the
elements occuring in the input stream and b is the type of
the elements in the output stream.
A Fudget is a special kind of stream processor which has high level streams and low level streams. The high level streams are used for connecting different parts of the program. The low level streams are used for communication with the world outside the program. For Fudgets implementing GUI elements, they can be thought of as being connected directly to the physical user interface element on the screen, allowing relevant mouse and keyboard events to be received through the input stream and appropriate drawing commands to be send through the output stream.
The type of a fudget is F
a b, where
a and b are the types of the high level input and
output streams, respectively. (The types of the low level streams are the
same in all fudgets and are thus not parameters of the Fudget type.)
buttonF
.
intDispF
.