Copyright | Copyright (c) 2009-2014, David Sorokin <david.sorokin@gmail.com> |
---|---|

License | BSD3 |

Maintainer | David Sorokin <david.sorokin@gmail.com> |

Stability | experimental |

Safe Haskell | None |

Language | Haskell2010 |

Tested with: GHC 7.8.3

This module defines a variable that is bound up with the event queue and that keeps the history of changes storing the values in arrays, which allows using the variable in differential and difference equations of System Dynamics within hybrid discrete-continuous simulation.

- data Var m a
- varChanged :: Var m a -> Signal m a
- varChanged_ :: MonadComp m => Var m a -> Signal m ()
- newVar :: MonadComp m => a -> Simulation m (Var m a)
- readVar :: MonadComp m => Var m a -> Event m a
- varMemo :: MonadComp m => Var m a -> Dynamics m a
- writeVar :: MonadComp m => Var m a -> a -> Event m ()
- modifyVar :: MonadComp m => Var m a -> (a -> a) -> Event m ()
- freezeVar :: MonadComp m => Var m a -> Event m (Array Int Double, Array Int a, Array Int a)

# Documentation

Like the `Ref`

reference but keeps the history of changes in
different time points. The `Var`

variable is safe to be used in
the hybrid discrete-continuous simulation.

For example, the memoised values of a variable can be used in the differential or difference equations of System Dynamics, while the variable iself can be updated wihin the discrete event simulation.

Only this variable is much slower than the reference.

MonadComp m => ResultComputing Var m |

varChanged :: Var m a -> Signal m a Source

Return a signal that notifies about every change of the variable state.

varChanged_ :: MonadComp m => Var m a -> Signal m () Source

Return a signal that notifies about every change of the variable state.

newVar :: MonadComp m => a -> Simulation m (Var m a) Source

Create a new variable.

readVar :: MonadComp m => Var m a -> Event m a Source

Read the recent actual value of a variable for the requested time.

This computation is destined for using within discrete event simulation.

varMemo :: MonadComp m => Var m a -> Dynamics m a Source

Read the first actual, i.e. memoised, value of a variable for the requested time actuating the current events from the queue if needed.

This computation can be used in the ordinary differential and difference equations of System Dynamics.

modifyVar :: MonadComp m => Var m a -> (a -> a) -> Event m () Source

Mutate the contents of the variable.

freezeVar :: MonadComp m => Var m a -> Event m (Array Int Double, Array Int a, Array Int a) Source

Freeze the variable and return in arrays the time points and corresponded first and last values when the variable had changed or had been memoised in different time points: (1) the time points are sorted in ascending order; (2) the first and last actual values per each time point are provided.

If you need to get all changes including those ones that correspond to the same
simulation time points then you can use the `newSignalHistory`

function passing
in the `varChanged`

signal to it and then call function `readSignalHistory`

.