
By now I've written a couple of implementations of (reply / response) protocols in Haskell. They all basically follow the same pattern: 1. One message type with a constructor for each, e.g. data Message = PingMsg | ... 2. One reply type with a constructor for each, e.g. data Reply = PingReply | ... 3. Any message or reply containing data has a constructor taking an argument of a type for that data, e.g. data Message = ... | SendDataMsg SendDataD | ... data SendDataD = SendDataD ByteString 4. The raw data is received from somewhere and passed through a parser written using attoparsec. 5. The messages are rendered into ByteString using ByteString.Builder. So, in essence something like this: +------+ +----------+ +-------+ +------------+ +------+ | read | --> | parse | --> | stuff | --> | render | --> | send | | raw | | into | +-------+ | to | | raw | +------+ | Messages | | ByteString | +------+ +----------+ +------------+ I'm curious to hear about other ways to handle protocols. Are there any papers written on implementing protocols using FP in particular? The protocols I've faced are rather simple things, what about more complicated ones, e.g. multi-layered protocols (ala IP - TCP)? /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus In order to understand recursion you must first understand recursion.