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

Dean Herington wrote:
At 6:41 PM -0700 3/21/08, Adam Langley wrote:
Also
getter <- fmap (amqpGetTable !) getWord8 getter
is just
fmap (amqpGetTable !) getWord8
I don't think so. Aren't there two "gettings": the first to get the "type" byte and the second to get the item?
Yes. I didn't use it because it seemed obfuscated, but in fact the point-free version is
fmap (amqpGetTable !) getWord8 >>= id
And I've also got an AmqpWire class similar to Dean's AmqpValue class. But both of these miss the point (which is why I didn't clutter up my simplified explanation with them). I'm looking for an alternative to the honking big AmqpVariant and AmqpArray types. I think I want something along the lines of:
class (Binary v) => VariantClass v where typeCode :: v -> Word8 fromVariant :: AmqpVariant -> Maybe v
newtype AmqpVariant = forall a . (VariantClass a) => Variant a
newtype AmqpArray = forall a . (VariantClass a) => AmqpArray [a]
But I can't see how to write "fromVariant". I'm also unsure what the "amqpGet" and "amqpPut" methods might look like. Or maybe these two types are actually the best design. They do let you pattern-match on the contents. Extracting the contents of a variant from the design above would be something like:
processVariant (Variant v) = case typeCode v of 0x01 -> processWord8 $ fromJust $ fromVariant v 0x02 -> ... and so on.
Compare this with:
processVariant (VariantWord8 v) = processWord8 v processVariant (VariantWord16 v) = processWord16 v ... and so on.
What do you think? Paul.

On Sat, 2008-03-22 at 16:08 +0000, Paul Johnson wrote:
Dean Herington wrote:
At 6:41 PM -0700 3/21/08, Adam Langley wrote:
Also
getter <- fmap (amqpGetTable !) getWord8 getter
is just
fmap (amqpGetTable !) getWord8
I don't think so. Aren't there two "gettings": the first to get the "type" byte and the second to get the item?
Yes. I didn't use it because it seemed obfuscated, but in fact the point-free version is
fmap (amqpGetTable !) getWord8 >>= id
Nah, the point-free version wouldn't be this. First, join = x >>= id so fmap (ampqGetTable !) getWord8 >>= id === join (fmap (ampqGetTable !) getWord8) Next, m >>= f = join (fmap f m) so join (fmap (ampqGetTable !) getWord8) === getWord8 >>= (ampqGetTable !) This would be the point-free version So the original code was a round-about way of saying: do word <- getWord8; ampqGetTable ! word
participants (2)
-
Derek Elkins
-
Paul Johnson