Serializable stable type representation

I am working on a data structure that I would like to serialize with an API like:

serialize :: Foo a -> ByteString
deserialize :: ByteString -> Maybe (Foo a)

In my case a, the phantom parameter; there are no values ​​in Footo witness this type, but persistence of the type is important.

GHC provides Typeable, which can give me a form TypeRepthat I can extract Fingerprint, but I do not believe that the presentation is necessarily stable in different architectures and versions of GHC.

Is there some way that I can reliably serialize a type representation, perhaps using a new article on static pointers or something else in base?

EDIT : I implemented this version control function (like "type hashing") in hashabler ; see TypeHash.

+4
source share
1 answer

, Typeable, binary-typed. . , , . - , , . Map TypeRep, , Int. , IntMap , .

+3

Source: https://habr.com/ru/post/1606303/


All Articles