Time difference in the reactimate (sense) function in Yampa
Asked Answered
C

1

7

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?

Courser answered 4/7, 2012 at 17:11 Comment(0)
M
1

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.

Monopetalous answered 21/7, 2012 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.