SerTH for Data.Map

Arie Peterson ariep at
Tue Feb 7 11:01:31 EST 2006


Having read about the SerTH library, I am now trying to use it in my

It works great for simple types. However, I ran into trouble when I tried
to serialise

> data S = S (Map Int Int)

; ghc complains that there is no instance for 'Serializable (Data.Map.Map
Int Int)'. I am not sure how to derive such an instance. I tried

> $(deriveSerializable ''Map)

, which gave
"Exception when trying to run compile-time code:
      ./Codec/Serialize/SerTH/BSerDerive.hs:(56,0)-(57,98): Non-exhaustive
patterns in function sdef".
Is this perhaps because 'deriveSerializable' cannot handle type constructors
with arguments?

Next I tried

> type MapIntInt = Map Int Int
> $(deriveSerializable ''MapIntInt)

, giving the same error message.

To investigate, I tried to serialise

> type Foo = Int

which did not work. However, it is possible to derive serialisation for

> data Bar = Bar Char Foo Int

with 'Foo' as above. So it seems that type synonyms can be serialised
indirectly, but not directly.

Could anyone give me a hint as to what I'm doing wrong? Or is what I'm
trying not possible with SerTH?

Thanks and greetings,

Arie Peterson

More information about the Libraries mailing list