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"
The following program has events that happen at the beginning of time, as they use
return
for theMonad Event
instant.one
returns aBehavior
who'sEvent
contains a deferredNow
computation. This computation in turn does some IO, and then samples theBehavior
passed in as an argument -two
- to obtain a subsequentEvent
containing another (possibly) deferredNow
computation. When thisEvent
occurs, theNow
computation is executed.However, when
one
is giventwo
, I would expect theNow
computation intwo
to be executed, as thatEvent
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 forplan
states:but that is not what I am seeing.
Code:
Output:
Expected output: