reactive-banana
reactive-banana copied to clipboard
Discrepancy in model and implementation
Just discovered this while trying to conjure Event a -> Event (Event a)
up for convenience.
Documentation states the semantics as:
once e = \time0 -> take 1 [(t, a) | (t, a) <- e, time0 <= t]
Note the time0 <= t
constraint, which means event occurrence at Moment
time is accepted.
However, once
is defined using switchE
.
once :: MonadMoment m => Event a -> m (Event a)
once e = mdo
e1 <- switchE e (never <$ e1)
return e1
Now, from switchE
we have
switchE e0 ee0 time0 =
concat [ trim t1 t2 e | (t1,t2,e) <- intervals ee ]
where
laterThan e time0 = [(timex,x) | (timex,x) <- e, time0 < timex ]
ee = [(time0, e0)] ++ (ee0 `laterThan` time0)
intervals ee = [(time1, time2, e) | ((time1,e),(time2,_)) <- zip ee (tail ee)]
trim time1 time2 e = [x | (timex,x) <- e, time1 < timex, timex <= time2]
The trim
function only allows event occurrence time1 < timex
.
Since the intervals ee
should start with [(time0, time1, e0), ..]
, by trim
occurrence of e0
before time0
is cut off!
According to this documentation, switchE e (never <$ e1)
should not produce any value at the Moment
time (time0
).
Hence, once
should drop event occurrence at the Moment
time / time0
.
I am utterly confused here, which one is right?