Tue May 4 11:47:53 EDT 2010
Representing (single) assignment
See previous posts for prelude. These ideas keep coming back:
- Lexical scope is good (stick to lambda/let for inputs)
- In addition, explicit outputs are necessary.
It seems I'm looking for some kind of abstraction of assignment.
I.e. the "output" operator.
The problems that comes up then is: what is the return type of a
function that performs bindings to outputs?
f (in1, in2) out = out <-- in1 + in2
Ha! It's the ``other side'' of the channel!
So the main abstraction I'm looking for is a channel with one input
and any number of outputs. Funny, this relates directly to the
DFL / reactive work in Scheme.
The type of `f' above is ... -> [Channel], or even a tuple. This
would then also bridge with the Arrow abstraction.
The problem is: how do you tie the two ends together? How do you
implement "connect". The flow of information is like:
A "patcher" creates a node which has two ends, passes the input
end as an output to a processor, and the output end as an input
to any number of processors.
The question is then: what is a channel? How to represent it?
Modeling a channel as a mutable object seems to make this simple. Can
it be modeled as a function? The important element is sharing.
Let's write `liftA2' for binary operators, or maybe Functor is enough
and simply use `mapf' for (x,x) -> x.
It seems that this needs a push or pull approach, i.e. we need to
"pick a side" of how to evaluate a network that's constructed by a
patcher. Pull seems safest and closest to how we represent channels
(model a network as its eventual output), so a channel is something
that converts a "network context" into a number, triggering evaluation
whenever a certain value isn't present yet.
This is a State monad. It's not a Reader monad since the context
(variable bindings) can and does change after an evaluation.
What we want to abstract is the memoization.
Full circle again: this is exactly the representation used in the
Staapl/Scheme approach to the dataflow problem.
So, let's restate: a channel is a State monad c->(v,c) where c is the