In Functional reactive chatter-bots, I described a few arrow-friendly formulations of functional reactive programming (FRP). This post shows how to define accumulation combinators and gives a few simple examples of their use.

Accumulators on lists

The various types of bots from the previous post all have in common that they map streams to streams. If the bots were simply functions on lazy lists, we would probably use the scanl combinator:

Our bots wait for input before producing output, so we’d want to drop the first element of the result (b0). (In a future post, we’ll meet some more assertive bots.) If we didn’t already have scanl, we might implement this new behavior as follows:

Mutant-bots

To see how to incorporate scanl into BotWorld, let’s start with the simpler mutant-bots. The implementation directly follows scanlTl, except that we drop the empty case, since we assume our input streams to be infinite.

How are we doing, and where are we going?

I’m encouraged with how simply accumulation works out. Most of the pieces of Reactive have chatter-bot counterparts now. The implementation doesn’t require multi-threading (as Reactive uses), so it was easy to get purely deterministic semantics.

Still to come:

Snapshot a varying value whenever an event occurs.

A clear notion of varying values (in progress).

GUI examples.

Source code release.

Work out how to use the arrow-styled interface with TV, which uses currying and pairing (in progress).