Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time difference in the reactimate (sense) function in Yampa

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?

like image 296
AsgarZigel Avatar asked Jul 04 '12 17:07

AsgarZigel


1 Answers

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.

like image 195
martingw Avatar answered Oct 03 '22 18:10

martingw