Replacing the world in a State Machine with IO

Hello all, at my shop some folks are implementing things using a java tool called "activiti". AFAIK, they create a bunch of processes and a "process engine" takes care of activating or deactivating processes. Among the things which can cause a state transition are external events. I wonder how one could do this in haskell. (1) Async IO I thought the collection of all process states can be seen as the system state of a state machine. Some state transitions can be done without doing IO, e.g. in situations where the termination of one processes immediatlely activates another process. However other transitions block and occur as soon as an external event is received. Yet other transitions occur WHENEVER an external event gets received. I suppose I could handle this using threads, but I don't trust threads. They look simple first, but then the trouble they cause typically exceeds my worst expectations. My primary problem is that I haven't yet found a proper way to fully capture the problem. It appears to me that a state machine without IO is essentially a discrete event simulation. A state machine where ALL state transitions are triggered by IO also seems easy, everything would be blocking and I just dispatch external events. But I cannot picture a state machine where some (but not all) transitions are triggered by IO. (2) Replacing the real world In the long run, I'd like to replace the "world" from which these events originate by a simulated world. This should allow the process engine to proceeed in fast motion. I suppose I will then also make the clock part of the simulated world. This raises the question: how does one replace IO? The simulated world will not do any real IO (but still communicate to the process engine). Considering that "IO a" basically means "World -> (World, a)" this should be easy, but I cannot see how to get a hold on "World". If someone could give my thoughts a push in the right direction, I'd much appreciate it.

On 23.11.2014 18:04, martin wrote:
at my shop some folks are implementing things using a java tool called "activiti". AFAIK, they create a bunch of processes and a "process engine" takes care of activating or deactivating processes. Among the things which can cause a state transition are external events. I wonder how one could do this in haskell.
Like a like a mini operating system: processes and their scheduler? Perhaps take a look at the following: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.8039 http://repository.upenn.edu/cgi/viewcontent.cgi?article=1391&context=cis_papers http://www.haskellforall.com/2013/06/from-zero-to-cooperative-threads-in-33....
I suppose I could handle this using threads, but I don't trust threads. They look simple first, but then the trouble they cause typically exceeds my worst expectations. In Erlang you woudn't think much and use (lightweight) processes and message passing. You can do the same in Haskell, just don't use global state, use channels instead.
I also recall https://hackage.haskell.org/package/aivika, discrete event simulation library, but I don't know if it is related. -- Wojtek
participants (2)
-
martin
-
Wojtek Narczyński