-
Notifications
You must be signed in to change notification settings - Fork 71
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
Idea: add a combinator to track when a behavior is a different value #265
Comments
Similar to Also, usually achievable with a |
Unfortunately I don't think such a combinator is actually permitted by the model. Recall that a |
Hmm, Time is discrete, right? So in the model you loop over every time value until it changes. If |
No, time is continuous. https://hackage.haskell.org/package/reactive-banana-1.3.1.0/docs/Reactive-Banana-Model.html states:
But I don't quite know what this means 🤔 |
Like, the actual implementation of the model represents behaviors as lists. And as long as behaviors are piecewise constant, detecting updates is still semantically meaningful (it's the set of discontinuities). |
It is desirable that behaviours appear continuous. Breaking that breaks the model. |
Hmm, what about a function that detects isolated discontinuities?
With the current implementation, it would be the same as Another name could be |
The thing is, Reactive Banana only samples behaviors on events anyway. So, you already have that event lying around, you may as well just re-use it (which is what a Take, for example, the If we just rely on internal events for sampling, and want our |
(err, pretend that the |
Oh, I forgot about The only thing I can think of is you somehow knew the maximum sampling frequency of the RAM, maybe that would suffice (what IO action could update faster than that)? idk |
(for pure values I know infinite search is possible (see this) but I think Unless maybe you change |
So, even with pure behaviours things get tricky, and you would need to begin relying on numerical methods to find discontinuities. These methods would also rely on the sampling behaviour, and could miss short discontinuities. Once you start down this road, you are no longer in interactive FRP, but more like an integration system based on FRP. I did have a prototype of such a library for modelling dynamical systems before, and the only way to trigger events was from zero crossings of the behaviour. It would also adjust the sampling frequency intelligently and perform a bisection search, jumping backwards in time as required to get within a desired accuracy of the root. While it's an interesting way of creating dynamical systems, one must always be on the lookout for tricky sample rate dependent gotchas. The beauty of continuous time FRP is that you just do not have to worry about any of that ever. Also, when sampling from the real world, it's kinda hard to guarantee anything. Using |
This post talks about exhaustive search, so you shouldn't be able to miss any discontinues, even the short ones. There is no sampling rate. It works very differently than a That being said, it appears that both |
But if you're curious about the details for how it would work for FRP without IO, here is the basic idea. I'll base it on this post, which is what the infinite search monad post was based on. Time would be Then you get something like
Note that |
I suggest a combinator with the following type signature.
updates :: Eq a => Behavior a -> Event (a, a)
When
b
changes,updates b
will fire and return(current, next)
, wherecurrent
is the current value andnext
is the different value it is changing into.nexr
should be used with caution to avoid infinite loops.Note for example that
updates (a <$ b)
should never fire even ifb
changes, becausea <$ b
will never sample different values.The text was updated successfully, but these errors were encountered: