views:

219

answers:

1

After reading about CCR : http://www.infoq.com/news/2008/12/CCR I get the impression that it does pretty much exactly the same as F# async blocks?

You yield port.Receive and port.Test in order to do the same as "let!".

Is this correct? And are there any benefits in CCR that you don't get with F# async?

+4  A: 

The example in the article you mentioned really looks just like let! from asynchronous workflows. In general, the yield return keyword in C# makes it possible to encode patterns similar to F# computation expressions (in a weird way, because it was designed for creating enumerators):

  • This is also used by AsyncEnumerator, which is (IMHO) simpler than CCR and a bit closer to F# asynchronous workflows
  • I wrote an article that explains this similartiy in more details.

I think that the key difference between CCR and F# asynchronous workflows is that CCR also includes libraries for message-passing concurrency. See for example this article - it uses Port class (you can send messages to ports) and Arbiter.Receive, which is a primitive that allows you to wait for messages from Port.

In F#, you can use MailboxProcessor for implementing the same message-passing communication pattern, but this isn't a built-in part of F# asynchronous workflows - MailboxProcessor is implemented using asynchronous workflows.

In summary: I think that F# asynchronous workflows are simpler and conceptually clearer. However, CCR and asynchronous workflows together with MailboxProcessor implement roughly the same programming pattern.

Tomas Petricek
How efficient would the F# MailboxProcessor be compared to Erlang processes?Even if there is more overhead than Erlang, it should be pretty much as good as it gets on the .NET platform when it comes to spawn cheap agents/processes, right?
Roger Alsing
The main difference is that MailboxProcessor is designed to run in a single process - not distributed on multiple processes/machines. I don't have any link to prove that, but I think I've seen some stats and the results (in this scenario) were comparable. Note that F# doesn't need to create thread for each MailboxProcessor (thanks to workflows).
Tomas Petricek
@tomas petricek : the companion library of ccr: the dss, allows for cross machine message posting making it more and more resembling erlang's features
Toad