-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simultaneity and merging/combining/sampling #145
Comments
I saw this same issue when implementing a "most" version of the kefir tree demo. I was using sampleWith... |
Hi Benawhite, What an interesting question. When we finished publishing the FrTime sequence of paper, I became convinced that a notion of simultaneous events was needed to make FRP work well in practice. When we implemented exploratory demo, the pattern that occurred frequently was decomposition-recomposition. It is a pattern which is natural when using functions which become oddly difficult in FRP.
This is natural:
This is also fine:
But once we start reconstructing, we run into trouble. So let's deconstruct:
Reconstructing using
|
@gmarceau Thank you for such an informative reply! I read it once, and I think I need to read it a few more times to fully absorb it. Planning to read again today :) Can you explain a bit more about value simultaneity? Is this a similar notion to how arrowized & signal vector FRPs use tuples or other tree structures to represent simultaneous events? |
I am glad you found it inspiring. Let me know if you have additional questions on the second read. Value simultaneity is firstly the title of a research project I would embark on given the time. It could be defined in multiple different ways and it would necessitate experimentation to discover the most practical definition. I am not intimately familiar with the tree representation you mention. If FrTime, we used mutable linked lists to represents event streams. Under every expression requiring evaluation, new events would be pushed as they occurred, and events would popped to start their processing at this expression. Most of these lists would be zero- or one-event long. But events produced faster than the processing rate at which they could be would accumulate in the streams, by design. The same representation worked for time-simultaneous events. Two pushes back-to-back on the same stream. In other words, we defined the semantics of FrTime intentionally to that let y = most.merge(x, x); would result in This is quite different from the notion of value simultaneity that's involved in the call the |
+1 |
How about the atomic updates approach from https://github.com/paldepind/flyd#atomic-updates ? |
Currently, simultaneous events are problematic. Here's a silly, but illustrative example:
What does it mean to merge x with itself? Currently, y will contain twice as many events as x. In effect, y synthesizes new events out of thin air. Another:
What does it mean to combine x with itself? Again, y will end up containing twice as many events, and imho, they will be unintuitive. For example, if you do
y.observe(a => console.log(a))
, it will log:Exactly every 10 ms, there is actually only one event, yet, combine will log two events.
I have no idea how common simultaneous events are in practice, but the above cases are certainly confusing, imho. I'd like to brainstorm potential solutions.
Transactional time with commit phase
See #144 for a particular line of thinking on how to resolve the combine problem, specifically. I'm not convinced it's the right thing, but it does help. It may be something we could do across the board, i.e. combinators that deal with multiple inputs could always wait until "end of current timeslot", some sort of timeslot commit phase, to make decisions on how to propagate events.
Merge combinator and monoids
For merging, some other (non-JS) reactive implementations use a merge combinator that requires either:
mconcat
, orIt seems interesting that 2 is quite similar to
combine
.Other affected combinators
Unfortunately, the problem doesn't end with merge and combine. It exists for any combinator that has deals with multiple input streams, where > 1 of those input streams may be active simultaneously. For example, simultaneous events can occur with
flatMap
, but not withconcatMap
.The text was updated successfully, but these errors were encountered: