How to implement CSP over agents in F #?

I wondered if it is possible (and desirable!) To implement CSP on top of F # agents. I think that if F # already has it and works well, it might be possible to just provide an API to simulate CSP with channels, ALT and similars ...

The main problem is that the agents are asynchronous and CSP blocks. Or how to implement CSP in F #?

PD: I found https://github.com/Hopac/Hopac , but I want to know how to implement it, for training and to avoid dependencies, if possible.

PD 2: I found an elixir sample at http://blog.plataformatec.com.br/2014/10/playing-with-elixir-and-go-concurrency-models/ and erlang https://gist.github.com/ kachayev / 5426175 .

0
f # agent
source share
1 answer

The Wikipedia article on sequential process exchange (CSP) contains a nice section that details key differences between CSP and the Actor model (F # Agents are based on the concurrency actor model). Two differences that stand out to you are absolutely necessary - synchronous and asynchronous, as well as recording on channels or a direct letter to the process.

It may be possible, but it looks difficult. At the most fundamental level, CSP requires completely synchronous communication between processes, while the F # agent (MailboxProcessor) is asynchronous, so you will need to create a system that forces synchronous communication between F # agents. A possible solution would be to use the PostAndReply function.

The following big difference (and perhaps the most difficult to overcome): CSP writes to a specific channel, while the F # actor model you write messages to a specific actor. In other words, if you have two processes A and B : using F # A agents, a message will be sent explicitly indicating B.post(<msg>) , while in CSP A will write a message to a channel named chan and B will It is said to read explicitly from a channel named chan (note that in CSP the communication channels are process independent, whereas in the F # agent model the communication channel is identical to the receiving agent). This seems like a much more difficult difference to overcome. Just giving up and thinking (I don’t know if this will actually work well): one possibility might be to rethink what the F # agent is: instead of the Agent acting as a process, there are agents that act as a CSP channel.

For anyone interested in CSP, Clojure core.async is based on CSP, and Brave Clojure has a pretty good tutorial that helps explain how CSP works.

+1
source share

All Articles