Implement a clock in a special monad m (or monad transformer) that ticks upon a particular side effect in m (depending on the clock value).
Other parts of the signal network that are also in m can then trigger events on this clock.
One crude implementation could go roughly like:
data MVarEventClock a = MVarEventClock (MVar a)
instance Clock IO MVarEventClock where
startClock (MVarEventClock var) = arrM_ getCurrentTime &&& arrM_ (takeMVar var)
triggerEvent :: MVarEventClock a -> a -> IO ()
triggerEvent (MVarEventClock var) = putMVar var
Care needs to be taken that triggerEvent does not lead to deadlocks when called from a signal on the same clock. Possibly, Chan or STM.TChan will give a more robust implementation.
Implement a clock in a special monad
m
(or monad transformer) that ticks upon a particular side effect inm
(depending on the clock value). Other parts of the signal network that are also inm
can then trigger events on this clock.One crude implementation could go roughly like:
Care needs to be taken that
triggerEvent
does not lead to deadlocks when called from a signal on the same clock. Possibly,Chan
orSTM.TChan
will give a more robust implementation.Is it possible to implement such a clock purely?