[Haskell] Composing channels

Setzer, Sebastian (ext) sebastian.setzer.ext at siemens.com
Tue May 22 14:55:28 EDT 2007


Hi,
Suppose you've got two tasks, A and B, A wants sends a request to B, B
sends a response. Both are sent through Control.Concurrent.Chan:
+---+                    +---+
| A |<--aChan    bChan-->| B |
+---+                    +---+
A writes to bChan, B writes to aChan.

Because B gets requests from several tasks, the request (and the type of
bChan) includes aChan.

As long as these tasks are threads of the same process, that's fine.

But what can you do if there's a network (or some other kind of IPC) in
between?

If you didn't need to respond, you could try something like this:
+---+            +---+           +---+            +---+
| A |    cChan-->| C |--network--| D |    bChan-->| B |
+---+            +---+           +---+            +---+
A sends to cChan. C serializes the request, D deserializes it and sends
to bChan.

If you want to respond, it gets difficult.

In order to send aChan through the network, you have to serialize it.
When deserializing it, you have to create a channel in the process of D
and B, which you can write into bChan and which B uses to respond. This
channel will be read by a task which serializes the response, sends it
through the network to the process of A and C, where it will be
deserialized and written to aChan.

Of course, you need to keep the serializing/deserializing in both
processes consistent. For example by using the same shared object.

Looks quite difficult. Are there any simpler solutions for typesafe
network-communications? Are there plans to include some kind of "network
transparent channels" in the haskell library (or are they already there
and I overlooked them)?

Sebastian Setzer


More information about the Haskell mailing list