12 Abstract fudgets

When using the Fudget library in a program, fudgets from the library are usually combined with some application-specific code, that is typically attached to the program in serial compositions. In the examples, we have seen the use of mapF and mapstateF for this:

facF = intDispF >==< mapF fac >==< intInputF
counterF = intDispF >==< mapstateF count 0 >==< buttonF "Up"
The functions mapF and mapstateF create abstract fudgets, that is, fudgets that do not perform any I/O. They communicate only via their high-level streams.

A more general way to construct abstract fudgets is provided by the function absF,

absF :: SP a b -> F a b
where SP is the type constructor for plain stream processors. These have a single input stream and a single output stream. The function absF creates a fudget by connecting the streams of a stream processor to the high-level streams of the fudgets, while leaving the low-level streams disconnected, as shown in Figure 21.

Figure 21. Turning a stream processor into an abstract fudget.

The functions mapF and mapstateF are in fact defined in terms of absF:

mapF = absF mapSP
mapstateF = absF mapstateSP
where mapSP and mapstateSP,

mapSP :: (a -> b) -> SP a b
mapstateSP :: (a -> b -> (a, [c])) -> a -> SP b c
are discussed in Section 16.2 and Section 16.3, respectively.

Although high-level combinators like mapF and mapstateF are adequate for most fudget application programming, some programmers may prefer the flexibility of the more basic ways of creating stream processors. Two examples where abstract fudgets are defined in terms of absF can be found in Section 32.4. An extensive discussion of stream processors can be found in Part III.