This example shows how to create parallel compositions of many fudgets of the same type.
This program extends the counter example with yet another button. You can now increment, decrement and reset the counter.
Here is the source code:
import Fudgets main = fudlogue (shellF "Up/Down/Reset Counter" counterF) counterF = intDispF >==< mapstateF count 0 >==< buttonsF data Buttons = Up | Down | Reset deriving (Eq) buttonsF = listF [(Up,buttonF "Up"), (Down,buttonF "Down"), (Reset,buttonF "Reset")] count n (Up,Click) = (n+1,[n+1]) count n (Down,Click) = (n-1,[n-1]) count n (Reset,Click) = (0,[0])
listF
than
>+<
.
The argument to listF
is a list of pairs of
adresses and fudgets. The adresses are then used when you
send messages to and receive messages from the components
in the composition.
Buttons
, the elements of which are used as the adresses of
the buttons. The messages received by the count
function
are pairs of Button
values and Click
s.