Generic serialization/deserialization in Haskell