[Haskell-cafe] AMQP framing layer: design help requested.

Adam Langley agl at imperialviolet.org
Fri Mar 21 21:41:47 EDT 2008


On Fri, Mar 21, 2008 at 11:02 AM, Paul Johnson <paul at cogito.org.uk> wrote:
>  This effectively duplicates the AmqpVariant solution.  It would work,
>  but it feels horrible.  I get the feeling that there ought to be a
>  better way, possibly using classes or existential types.  Any suggestions?

Firstly, I would use the Get and Put monads directly, rather than
making them instances of Binary. I think, if I were doing it, I would
start off with something like this:

class AMQPValue a where
  putAMQP :: a -> Put

instance AMQPValue Word8 where
  putAMQP v = putWord8 1 >> putWord8 v
... (many instances)

instance (AMQPValue a) => AMQPValue [a] where
 putAMQP vs = putWord8 (length vs) >> mapM_ putAMQP vs

You probably want a getAMQP member of the AMQPValue class too.

Also
>   getter <- fmap (amqpGetTable !)  getWord8
>   getter

is just

> fmap (amqpGetTable !)  getWord8

Hope that helps some


AGL



-- 
Adam Langley agl at imperialviolet.org http://www.imperialviolet.org


More information about the Haskell-Cafe mailing list