See also the various papers by Hancock and coauthors about interactive programs in type theory, and stream processing (and hence back to the original stream-based IO models of Landin, KRC, Miranda(TM), precursors to haskell, as well as the underlying data and control model of Jackson Structured Programming (JSP)), esp.:
Representations of Stream Processors Using Nested Fixed Points
UPDATED: the reference offered analyses the following two scenarios/specifications: those of
- a continuous (ie., computable)function from
Stream I
to O
, for inputs of type I
, and outputs of type O
(the paper uses A
and B
, sorry)
- a continuous function from
Stream I
to Stream O
By somewhat 'elementary' (philosophical) considerations (plus allusions to the Bar Theorem of Brouwer), the first situation is shown to reduce to considering well-founded I/O trees, with leaves in O
, and branching factor I
, ie to T(I,O) = mu X. O + (I -> X)
: at each step of the computation, either immediately return the answer o : O
, or else continue by polling the input stream for an additional input i : I
...
The second is (only a bit) more subtle, and perhaps can best be understood as asking how to build results in Stream O =def nu Y. O x Y
by coinduction, ie by showing how to compute the first output observation o : O
, and then how to compute the rest of the output stream. The first part reduces to the first scenario, so roughly you end up with Stream I -> Stream O
represented by non-well-founded processes P(I,O)
built out out of finite well-founded trees, as
P(I, O) =def nu Y. mu X. (O x Y) + (I -> X))
The T(I,O)
abstraction corresponds to the well-founded part of the resumption domain equation, and the P(I,O)
abstraction to an iterated/nested fixed-point, rather along the lines (I think) of Andy Pitts' analysis (following Freyd) of mixed variance domain equations.
Hancock, Setzer, Hyvernat and others explored the rich algebra of the T(I,O)
construction (under the name 'interaction structures' or 'command-response interfaces')) in the case where at each input i : I
, the range of possible outputs O i
is allowed to depend on i
. The type of such trees was first introduced by Petersson and Synek in (1989) as an indexed/dependent generalisation of W-types in Martin-Lof's type theory and has a rich theory in modern times via indexed/dependent containers/polynomial functors.
The relationship between JSP and the T(I,O)/P(I,O)
constructions is discussed in various places, but most recently to my knowledge in Oleg Kiselyov's slides on stream fusion from a recent IFIP WG2.1 meeting, as well as in earlier work.