Skip to content

Commit

Permalink
Merge pull request #282 from HeinrichApfelmus/seq-network
Browse files Browse the repository at this point in the history
prevent let-floating trick tweak: swap `const m r` for `seq r m`
  • Loading branch information
mitchellwrosen authored Feb 25, 2023
2 parents 84f0bd4 + 2f4b6da commit 58596df
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions reactive-banana/src/Reactive/Banana/Prim/High/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ liftBuild = lift
Interpretation
------------------------------------------------------------------------------}
interpret :: (Event a -> Moment (Event b)) -> [Maybe a] -> IO [Maybe b]
interpret f = Prim.interpret $ \pulse -> runReaderT (g pulse) undefined
where
interpret f xs = do
-- This event network is unused, but it can't be undefined due to the seq in cacheAndSchedule
eventNetwork <- compile $ pure ()
Prim.interpret (\pulse -> runReaderT (g pulse) eventNetwork) xs
where
g pulse = runCached =<< f (Prim.fromPure pulse)
-- Ignore any addHandler inside the Moment

Expand Down Expand Up @@ -177,7 +180,7 @@ trim b = do
-- and make sure that it is performed in the Build monad eventually
cacheAndSchedule :: Moment a -> Moment (Cached Moment a)
cacheAndSchedule m = ask >>= \r -> liftBuild $ do
let c = cache (const m r) -- prevent let-floating!
let c = cache (r `seq` m) -- prevent let-floating!
Prim.buildLater $ void $ runReaderT (runCached c) r
return c

Expand Down

0 comments on commit 58596df

Please sign in to comment.