[Haskell-cafe] When using Cereal, what is the right way to write `get` for multi-constructor type?
Magicloud Magiclouds
magicloud.magiclouds at gmail.com
Tue Apr 26 05:39:46 UTC 2016
Hi,
Say I have code already like:
data STH = A
| B
| C
instance Serialize STH where
put A = putWord8 1
put B = putWord8 66
put C = putWord8 111
Then what is the better way to do `get`? Is following the only one?
get = do
i <- getWord8
case i of
1 -> return A
66 -> return B
111 -> return C
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160426/50cce8fc/attachment.html>
More information about the Haskell-Cafe
mailing list