This example shows how to handle input from more than one source.
The two buttons affect the same counter.
Here is the source code:
import Fudgets main = fudlogue (shellF "Up/Down Counter" counterF) counterF = intDispF >==< mapstateF count 0 >==< (buttonF "Up" >+< buttonF "Down") count n (Left Click) = (n+1,[n+1]) count n (Right Click) = (n-1,[n-1])
The Up/Down Counter is a small extension of the Up Counter. We have added a button by replacing
buttonF "Up"
with
(buttonF "Up" >+< buttonF "Down")
using the operator
>+<
for parallel composition
The output from a parallel composition is the merged output from
the two components. Output from the left component is tagged
Left
and output from the right component is tagged
Right
.
The count
function will now receive
Left Click
or Right Click
, depending
on which button was pressed. It has been adjusted accordingly.
Everything else is as in the previous example.