[Haskell-beginners] Haskell Serialization

Daniel Fischer daniel.is.fischer at web.de
Wed May 12 13:35:11 EDT 2010


On Wednesday 12 May 2010 19:15:42, Ashish Agarwal wrote:
> >>     get (0::Word8)
> >>     getWord8be 0
> >
> > Make that
> >
> > put (0 :: Word16)
> > putWord16be 0
> >
> > ?
>
> Yes, thanks for the correction. Word8 was a bad choice since endianness
> is not an issue.
>
> Thanks for all the advice. It seems I should avoid making my types
> instances of Binary.

I wouldn't go so far, just stop and think before you do.

> In fact, this relates to another design issue I've
> been grappling with, supporting multiple versions of the protocol.
> Probably I'll need something like, putProtVersion1, putProtVersion2,
> etc. Or something along this line.
>

That, or

data Protocol a
    = Prot
    { putVal :: a -> Put
    , getVal :: Get a
    }

ieee754 :: Protocol Double
ieee754 = Prot { putVal=... , getVal=... }

json :: Protocol JSON
json = ...

work args = do
    stuff
    mapM_ (putVal prot) vals
    moreStuff


More information about the Beginners mailing list