Thu Oct 20 14:11:24 EDT 2011

Representing I/O as consumer functions.

What about making I/O a kind of function call.  If we're folding (s,i)
-> (s,o) then the recursive call that feeds the state back could be
something like (s,o) -> (s,i), a dual "consumer" that takes the output
and produces a new input.

So instead of just:

  state1 = ...;
  state2 = ...;
  goto tick;

we do something like:

  *oport1 = out1;
  *oport2 = out2;

  in1 = *iport1;
  in2 = *iport2;
  state1 = ...;
  state2 = ...;
  goto tick;
where the first block stores the output, and the second call is
actually passes input and state arguments.

Maybe not.. this doesn't have the correct symmetry.  Where does the
first input come from?

It's probably best i stick to the stream analogy.  While in Haskell we
might use a pair that is passed around as a parameter, it's probably
best to do something simpler but use some virtual representation of a
pair, i.e. a pointer or a pointer+index combo.

Trouble here is that we can't use the return value, so the fold would
have to be a left fold, where the "cons" can be represented as a write
to an array.