Inspired from here: https://blog.functorial.com/posts/2018-04-08-Incrementally-Improving-The-DOM.html
The blog posts has a concept a
Jet a which is a value paired with a description of the change that will happen to that value. Functions of type
Jet a -> Jet b form incremental functions, you have the extra information about what changed in
a to allow you to describe what changes in
b which can be propagated all the way down to the DOM, providing another information to manipulate only the parts of the DOM that need to change via destructive updates. If you read Phil Freeman's post above you'll get a better idea.
Jet a s can be thought of as dual values, I'll use the word refer to them as duel below, because Jet might get confused with describing an aircraft if used in project.
Here is some pseudo code that demonstrates pattern I propose for doing incremental lambda calculus in sodium.
Stream<DA> sDA; // <-- defined elsewhere, represents a change to A
StreamLoop<A> slA = new StreamLoop<>();
Cell<A> ca = slA.hold(initA);
Stream<Tuple<A,DA>> sDuelA = sDA.snapshot(ca, (DA da, A a) -> new Tuple(a, da));
slA.loop(sDuelA.map((Tuple<A,DA> duelA) -> patchA.apply(duelA._1(), duelA._2()));
StreamLoop<B> slB = new StreamLoop<>();
Cell<B> cb = slB.hold(nonIncrementalVersionOfF.apply(initA));
Stream<Tuple<B,DB>> sDuelB = sDuelA.snapshot(cb, incrementalVersionOfF);
slB.loop(sDuelB.map((Tuple<B,DB> duelB) -> patchB.apply(duelB._1(), duelB._2());
This pattern allows
cB to be incrementally updated from a change to
As an example of what the types of
A could be an
Array Int, and
DA could be a description of changes to that array like
ArrayChanges Int where
type ArrayChanges a = [ArrayChange a], and
data ArrayChange a = InsertAt Int a | DeleteAt Int | UpdateAt Int (a->a)`
DB could be describing the DOM or some half way intermediate data structure.
OK. The pseudo code I've given is very messy indeed. But maybe a cleaner abstraction can be made by wrapping some of the FRP objects up in a data structure and make a FRP kinda Jet.
Sorry if this post does not read well. It is a bit rushed.
Any ideas on building an abstraction are welcome.