I am learning Haskell and Yampa at the moment and have a question about the reactimate function.
reactimate :: IO a -- init
-> (Bool -> IO (DTime, Maybe a)) -- sense
-> (Bool -> b -> IO Bool) -- actuate
-> SF a b -- signal function
-> IO ()
As you can see in the type signature, part of the output for the sense function is the time difference between the current and previous call of the function. In the examples I have seen, this time difference is "manually" calculated inside of sense, using an IORef to keep the value of the previous call.
It seems weird that you have to keep track of the time difference using an external state, why isn't this calculation done in the reactimate function? Is an IORef a good way to handle it?
I would think the reason that reactimate does not calculate the time delta itself is that this would hard code one specific notion of time. Imagine you want to simulate portfolio risk over a ten year period or something like this, and your time delta resolution should be one day. This being said, I agree the Ioref thing looks kind of hacky, though I used the same technique in my code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With