reflex-frp / reflex

Interactive programs without callbacks or side-effects. Functional Reactive Programming (FRP) uses composable events and time-varying values to describe interactive systems as pure functions. Just like other pure functional code, functional reactive code is easier to get right on the first try, maintain, and reuse.
https://reflex-frp.org
BSD 3-Clause "New" or "Revised" License
1.06k stars 143 forks source link

Report Dynamic-based causality loops better #120

Open ryantrinkle opened 7 years ago

ryantrinkle commented 7 years ago

When a causality loop is created by joining a Dynamic whose contents depend on itself, reflex reports this as

<interactive>: heightBagRemove: Height 1 not present in bag HeightBag {_heightBag_size = 2, _heightBag_contents = fromList [(0,1)]}
CallStack (from HasCallStack):
  error, called at src/Reflex/Spider/Internal.hs:1015:14 in reflex-0.5.0-4m111lPPOvPBxxVtye35C3:Reflex.Spider.Internal

Ideally, it should report this as a causality loop explicitly, instead.

Here's some code that exhibits the problem:

{-# LANGUAGE RecursiveDo #-}

import Control.Monad
import Reflex.Dom

main = mainWidget $ do
  postBuild <- getPostBuild
  rec dd <- holdDyn (constDyn ()) (d <$ postBuild)
      let d = join dd
  performEvent_ $ return <$> updated d
ryantrinkle commented 5 years ago

That's a good old traditional Haskell loop - no FRP involved. 'sample b' is being used to initialize 'dyn', which is where 'b' comes from. Pretty nearly the same as rec r <- newIORef =<< readIORef r

On Thu, Aug 30, 2018 at 7:44 PM Kosyrev Serge notifications@github.com wrote:

This makes me wonder -- what would be the semantics of the following?

loopDyn = mdo let b = current dyn e ← delay 0 $ updated dyn dyn ← buildDynamic (sample b) $ tag b e pure dyn

I found that it hangs my (reflex-glfw-based) Reflex host, preventing it from processing events -- but doesn't cause a cpu busyloop.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/reflex-frp/reflex/issues/120#issuecomment-417503074, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGlYJCtMBBhhh31Y5Y_EnHLxHJlAWj0ks5uWHjYgaJpZM4OQUM0 .