Comments (4)
I also note that if I don't have reactimate $ print <$> b' <@ onPrint
then I don't get a sampling
message at all. This surprises me, because [Note LatchStrictness]
states that all latches (and thus I would expect all Behavior
s) should be in WHNF at the end of network evaluation - but that doesn't seem to actually be happening.
from reactive-banana.
A smaller repro:
{-# language BlockArguments #-}
module Main where
import Data.Functor
import Debug.Trace
import Reactive.Banana
import Reactive.Banana.Frameworks
main :: IO ()
main = do
(onChangeCheckbox, changeCheckbox) <- newAddHandler
actuate =<< compile do
onToggle <- fromAddHandler onChangeCheckbox
checked <- stepper False onToggle
let b1 = traceShowId <$> pure "1"
let b' = liftA2 (,) checked b1
reactimate $ return () <$ b' <@ onToggle
changeCheckbox True
changeCheckbox False
changeCheckbox True
Note that changing b1
to be b1 = pure $ traceShowId "1"
there is no problem. Also, changing b'
to be let b' = traceShowId <$> pure 1 <* checked
also doesn't have a problem. It seems to be something specific about having a separate b1
binding that uses fmap
.
I also tried let b' = b1 <* checked
and this also doesn't have the problem
from reactive-banana.
Another weird point: let b' = liftA2 (,) b1 checked
does not have a problem, but let b' = liftA2 (,) checked b1
does. So the order here seems to matter. Probably need to get into core at this point.
from reactive-banana.
I made some progress on understanding this one.
Here's a rough diagram of a slightly simplified version of Ollie's example.
The black text are latches, with nodes in the tree being <*>
pointing at the left and right side.
The red arrow shows an onToggle
event coming in and affecting the value of the checked
latch directly.
We need to calculate the value of the entire latch (the root of the tree), so we will go down depth-first, getting each latch's value, per the definition of applyL
and cachedLatch
:
reactive-banana/reactive-banana/src/Reactive/Banana/Prim/Mid/Plumbing.hs
Lines 107 to 117 in 58596df
So, say the event occurs at time t=5. When evaluating the whole latch, after getting to the checked
child, we'll write t=5 to the evaluation context, since it was directly updated by the event. (The EvalL
monad is WriterT Time IO
; the time indicates the latest time that this evaluation is recent as of).
Then, later nodes in the tree (such as our traceShowId <$> pure "1"
, which we expect to be unaffected by the onToggle
event and thus not recomputed, enter the same evaluation logic
reactive-banana/reactive-banana/src/Reactive/Banana/Prim/Mid/Plumbing.hs
Lines 110 to 117 in 58596df
only in a context where t=5 is already written to the EvalL
context. We'll therefore hit the else-branch which corresponds to recomputing this value rather than using what's cached.
from reactive-banana.
Related Issues (20)
- `reactive-banana` can't be compiled on GHC 9.2 HOT 2
- I created a Matrix channel HOT 8
- An interesting `Applicative`-ish way of combining `Event`s HOT 4
- Add `MonadMoment` instances for all monad transformers in `transformers` HOT 1
- Release 1.3.0.0 HOT 3
- Join Stackage HOT 4
- Unexpected memory growth HOT 6
- Event handler not seeing early events. HOT 12
- `Behavior`s can hold onto more memory than they need to HOT 2
- Memory leak with dynamic behavior switching HOT 16
- Gloss GUI events not responding HOT 5
- Idea: add a combinator to track when a behavior is a different value HOT 14
- Call `unregister` for garbage collected events made by `AddHandler`. HOT 9
- Discrepancy in model and implementation HOT 15
- Optimize representation of Latch HOT 1
- Not compatible with these-1.2 (disallowed) HOT 2
- Simultaneous events can have undefined behavior within execute HOT 2
- source-code formatter? HOT 2
- Accept deepseq-1.5 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactive-banana.