Skip to content

Signals created during an update phase doesn't get updated #3

merged 1 commit into from Dec 22, 2011

2 participants


Hi. I found a bug while playing with elerea. If a signal is created during an update phase, it doesn't get updated until the next iteration. The following code demonstrates the problem: it should print "0 2" but it prints "0 1". The reason is that the signal named "problem" doesn't get updated during the first iteration.

import Control.Applicative
import Control.Monad
import FRP.Elerea.Simple

andthen :: a -> a -> SignalGen (Signal a)
andthen x y = delay x (pure y)

zero :: Signal Int
zero = pure 0

makeProblem :: SignalGen (Signal Int)
makeProblem = do
  problem <- 1 `andthen` 2
  return problem

test :: SignalGen (Signal Int)
test = do
  dyn <- generator $ pure makeProblem
  prevDyn <- delay zero dyn
  sig <- zero `andthen` join prevDyn
  return $ join sig

main = do
  sample <- start test
  sample >>= print
  sample >>= print
cobbpg commented Dec 22, 2011

I see the problem now. Indeed, it’s quite insidious: the original single traversal cannot deal with deep indirections in the signal spawning process, and you delay the finalisation phase until it is clear that no more updates are possible. Thanks for the fix!

I think I’ll also add a module with the pure reference implementation under each of the variants. It might be useful in validating the behaviour in the future.

@cobbpg cobbpg merged commit 5e2c77f into cobbpg:master Dec 22, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.