Actually I didn't really want to focus on value / update.
My point in the original post was that you cannot switch (aka do a monadic join) on a behaviour, but that's not true (I checked the papers again; Behaviour is conceptually a Monad, just Elliot's representation in his opinion wan't compatible with Monad).
I'll try to visually explain what I mean by saying that Sodium cells are conceptually discrete. With a simple combination of mapC, accum, and switchC I was able to build an example where cell cB
is obviously reacting to a changes in cA
, even when A1 == A2 (I assume it would be impossible with continuous behaviuors/cells) .
const a = new StreamSink<number>();
const b = new StreamSink<number>();
const cA = a.hold(0);
const cB = Cell.switchC(cA.map(a => b.accum(a, (x, y) => x + y)));
cA.listen((a) => console.log(`a = ${a}`));
cB.listen((b) => console.log(`b = ${b}`));
b.send(1);
b.send(1);
b.send(1);
console.log("transaction {");
Transaction.run(() => {
a.send(2);
b.send(1);
});
console.log("}");
b.send(1);
b.send(1);
console.log("transaction {");
Transaction.run(() => {
a.send(2);
b.send(1);
});
console.log("}");
b.send(1);
b.send(1);
Maybe that's not a property of switchC, but hold (and the fact it discards all the values before time of its creation)? Maybe it's the fact that the lambda passed to mapC has (semantically) access to current time? I'm not sure yet, but I'm pretty sure that something in Sodium makes cells semantically discrete even if value/update didn't exist.
Or maybe the example I provided is not semantically correct, and I'm experiencing implementation details?