
Hello, Having read about the SerTH library, I am now trying to use it in my application. 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

Hello Arie, Tuesday, February 07, 2006, 7:01:31 PM, you wrote:
$(deriveSerializable ''Map)
AP> , which gave AP> "Exception when trying to run compile-time code: AP> ./Codec/Serialize/SerTH/BSerDerive.hs:(56,0)-(57,98): Non-exhaustive AP> patterns in function sdef". it works ok for me. ghc 6.4.1/mingw32, http://www.cs.helsinki.fi/u/ekarttun/SerTH/SerTH-0.2.tar.gz cmdline: "ghc -fth hello.hs --make -cpp" contents of hello.hs: import Codec.Serialize.SerTH import Data.Dynamic import Data.Typeable import System.IO import Data.Map $(deriveSerializable ''Map) btw, my Streams library include AltBinary part with TH-derived instances. i will announce it in few days -- Best regards, Bulat mailto:bulatz@HotPOP.com

Bulat, thanks for your quick reaction. It turns out that I imported "Data.Map" qualified (as "Map") and had "Map" defined as
type Map = Map.Map
. This type synonym was what SerTH stumbled on. Deriving the "Serializable" instance using the real name "Map.Map" solved it. Sorry to bother you with this. Regards, Arie

Hello Arie, Tuesday, February 07, 2006, 10:47:12 PM, you wrote: AP> Bulat, thanks for your quick reaction. i know his code good enough because i borrowed it for my own TH support ;) AP> It turns out that I imported "Data.Map" qualified (as "Map") and had "Map" AP> defined as
type Map = Map.Map
AP> . This type synonym was what SerTH stumbled on. Deriving the AP> "Serializable" instance using the real name "Map.Map" solved it. yes, this code don't support deriving via type synonyms. i will add this to my own TH support, just for fun :) -- Best regards, Bulat mailto:bulatz@HotPOP.com
participants (2)
-
Arie Peterson
-
Bulat Ziganshin