[Haskell-cafe] Binary parser combinators and pretty printing
ekarttun at cs.helsinki.fi
Thu Sep 15 16:20:23 EDT 2005
On 15.09 21:53, Bulat Ziganshin wrote:
> EK> data Packet = Packet Word32 Word32 Word32 [FastString]
> well. you can see my own BinaryStream package at http://freearc.narod.ru
> class BinaryData a where
> read :: ...
> write :: ...
I don't think this is a very good solution. Keeping the on-wire datatypes
explicit makes sense to me. Also things like endianess will need to be
taken into account. If the encoding is derived automatically then
changing the Haskell datatype will change the on-wire representation.
This is not wanted when interfacing with external protocols.
For typeclasses I would rather have:
getWord32BE :: Num a => MyMonad a
get :: MyClass a => MyMonad a
Note the difference between the Haskell type determining the on-wire
type and it being explicit. I already have working TH code for the
case where I want to derive automatic binary serialization for
Haskell datatypes (SerTH).
> EK> Maybe even the tuple could be eliminated by using a little of TH.
> it may be eliminated even without TH! :+: and :*: should work,
> although i don't tried this
I don't know how generics work in newer versions of GHC, but
it may be worth investigating.
- Einar Karttunen
More information about the Haskell-Cafe