[Fudgets Home Page]

An Up/Down/Reset Counter

This example shows how to create parallel compositions of many fudgets of the same type.

[Your browser doesn't support fupplets. Here is a window dump instead:]

[Window dump of the Up/Down/Reset Counter]

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])

Things to note

  • Next Example
  • Previous Example
  • Back to the Example list