[Haskell-cafe] How to make asynchronous I/O composable and safe?

Bardur Arantsson spam at scientician.net
Sat Jan 14 12:48:30 CET 2012

On 01/14/2012 11:42 AM, Joey Adams wrote:
> On Sat, Jan 14, 2012 at 1:29 AM, Bardur Arantsson<spam at scientician.net>  wrote:
>> So, the API becomes something like:
>>    runSocketServer :: ((Chan a, Chan b) ->  IO ()) ->  ... ->  IO ()
>> where the first parameter contains the "client logic" and "A" is the type of
>> the messages from the client and "B" is the type of the messages which are
>> sent back to the client.
> Thanks, that's a good idea.  Even if I only plan to receive in one
> thread, placing the messages in a Chan or TChan helps separate my
> application thread from the complexities of connection management.

Unless TCP is an absolute requirement, something like 0MQ[1,2] may be 
worth investigating.

It handles all the nasty details and you get a simple message-based 
interface with lots of nice things like pub-sub, request-reply, etc. etc.

[1] http://hackage.haskell.org/package/zeromq-haskell-0.8.2
[2] http://www.zeromq.org/

More information about the Haskell-Cafe mailing list