[Haskell-cafe] How to use FRP for Simulation

martin martin.drautzburg at web.de
Sat Jan 20 14:12:20 UTC 2018


Hello all,

the answer to the question "what is FRP good for?" often includes "simulation".

I somewhat understand the "reactive" situation, where an FRP system receives Events from the outside world and computes
Events to be sent to the outside world. To do so, the computation uses Behaviors which are essentially time-varying states.

I also read, that the programmer should not be allowed to literally define Events and Behaviors, or she might end up
writing bad prograns which exhibit time or space leaks. She should only be allowed to define transformations.

Now in a discrete event simulation (DES) there is a lot of "event stuff" going on and FRP looks like a good paradigm.
However, in a simulation nothing comes from the outside world and not much goes to the outside world. There is a
simulation result, but it is just a result like any other and doesn't have much to do with Time. A DES is not really a
reactive system at all.

In DES there is typically a set of initial Events and more events are created as the simulation progresses. I cannot see
how this can be done without the power to explicitly create Events. Also these Events point to the "future" and must
therefore carry an explicit (simulated) Time, whereas (IIRC) in FRP, Events do not necessarily carry an explicit Time.
They just occur, and if you need the time, you look at the clock (a Behavior Time).


So what exactly is meant by "FRP is useful for simulation". Does it mean that a DES engine can be written in FRP style
or does it mean something else?

If one can indeed write a DES engine in FPR style, what is the correct way of thinking about it?


More information about the Haskell-Cafe mailing list