paf31 / purescript-incremental-functions

Incremental lambda calculus
MIT License
80 stars 8 forks source link

Loss of incremental computation in a long chain of incremental functions #8

Open clinuxrulz opened 6 years ago

clinuxrulz commented 6 years ago

First of all Congratulations on your purescript-incremental-functions / purescript-purview. You've managed to completely eliminate the need for virtual dom diffing. However it seems like the entire dom model is still calculated each time, and the final real dom is then updated incrementally. This is still good because in frameworks like React you still do calculate the entire virtual dom, then a diffing algorithm is executed to modify only a part of the real dom. So you've still saved on diffing the dom.

There might be a way to update each intermediate state incrementally a long a chain of incremental functions.

Currently you have data Jet a = Jet a (Change a). Giving a incremental function from a to b the following form (a,Δa) -> (b,Δb). Say your composing some functions together E.g.

f :: (a,Δa)->(b,Δb)
g :: (b,Δb)->(c,Δc)
h :: (c,Δc)->(d,Δd)
r = h . g . f

Each time a new Δa fires down the chain of functions, b is recalculated, c is recalculated and d is recalculated. The functions need some way of maintaining the last a, b, c for reuse on the next iteration.

Now if we change the definition to something like:

data IncF a b = IncF (a -> (b, IncF2 a b))
data IncF2 a b = IncF2 (Δa -> (Δb, IncF2 a b))

Then we will lose HOAS, leading to the end-user having to use point-free notation.

Something else can be done:

data Jet a = Jet (Cell a) (Stream (Change a))

Cell and Stream are from a FRP library of your choice. You can now compose incremental functions, have access to past values of a, b and c. And also you get to keep HOAS.

The FRP library you choose would have to support forward references, and I'd recommend the ability to handle simultaneous stream events (i.e. can bust Stream (a,b) into Stream a, and Stream b, and combined those back into Stream (a,b) that works exactly the same as the original.)

I'd recommend a purescript wrapper arround the typescript version of sodium. And not the purescript-sodium I wrote years ago, its operational semantics are not correct.

clinuxrulz commented 6 years ago

You have also done some really nice work here: https://gist.github.com/paf31/5c1279796d66fe04a177e34b0d674ac6 That would restore HOAS for IncF definition above. Just would require the end-user to use the lam function when he is making a lambda.