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.


_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to