atzeus / FRPNow

Other
89 stars 14 forks source link

Plan from within a plan not executed #10

Closed ocharles closed 9 years ago

ocharles commented 9 years ago

The following program has events that happen at the beginning of time, as they use return for the Monad Event instant. one returns a Behavior who's Event contains a deferred Now computation. This computation in turn does some IO, and then samples the Behavior passed in as an argument - two - to obtain a subsequent Event containing another (possibly) deferred Now computation. When this Event occurs, the Now computation is executed.

However, when one is given two, I would expect the Now computation in two to be executed, as that Event has already happened. However, instead I observe that the computation is never executed.

I think there is a bug, because in one I check whether the event has occurred and am told that it has. The documentation for plan states:

If the event has already occured when planNow is called, then the Now computation will be executed immediatly.

but that is not what I am seeing.

Code:

module Main where

import Control.FRPNow

one
  :: Behavior (Event (Now ()))
  -> Behavior (Event (Now ()))
one children =
  pure (pure (do sync (putStrLn "plan for one")
                 childrenChanged <- sample children
                 sync . print =<< sample (hasOccured childrenChanged)
                 plan (fmap id childrenChanged)
                 return ()))

two :: Behavior (Event (Now ()))
two =
  pure (pure (sync (putStrLn "two")))

main :: IO ()
main =
  do runNowMaster
       (do change <- sample (one two)
           plan (fmap id change))
     putStrLn "All done"

Output:

plan for one
True
All done

Expected output:

plan for one
True
two
All done
atzeus commented 9 years ago

Thanks for the bug! Looking into it!

atzeus commented 9 years ago

Fixed!

atzeus commented 9 years ago

Will be in 0.15 in