[Haskell-cafe] Design of protocol implementation?

Magnus Therning magnus at therning.org
Thu Mar 5 10:42:03 UTC 2015


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 at therning.org   jabber: magnus at therning.org
twitter: magthe               http://therning.org/magnus

In order to understand recursion you must first understand recursion.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150305/fd7a9f3d/attachment.sig>


More information about the Haskell-Cafe mailing list