[Hs-Generics] xml deserialization using generics?

oleg at pobox.com oleg at pobox.com
Tue Jul 3 03:33:21 EDT 2007


Hugh Perkins wrote:
> Unfortunately I cant seem to run it.  It comes up with strange typing
> messages when compiling:
> *TestDeserialize> serialize P

> <interactive>:1:0:
>     No instance for (LDat (TL_red [a])
> ...
> where P is:

> getP = P "Lammel" "Amsterdam"

> (for simplicity)

> Similar looking errors with genCom, and/or with deserialize.

> I guess I need to add an instance or deriving statement to the P class?

You have encountered a bit confusing behavior of GHCi. If you put 

> getP = P "Lammel" "Amsterdam"
> t2 = serialize getP

into the file Deserialize.hs, which you then load into GHCi, you can
type "t2" at the GHCi prompt and see the expected result. OTH, typing
"serialize getP" at the GHCi prompt gives the error you reported. This
is a well known issue with GHCi: it uses the flags given in the
OPTIONS_GHC pragma when interpreting files, but forgets these flags
when interpreting expressions typed at the prompt. I think this
a bit confusing behavior started since GHC 6.4.0. 

So, you could place any complex expression in a file and load that
into GHCi (Haskell Emacs mode makes this quite convenient), or start
your GHCi with appropriate flags (at least, -fglasgow-exts). The third
alternative is to help GHCi by defining serialize like the following

> serialize1 xs = 
>   gapp (TL_red (concat::[[String]]->[String])) primitive_fields_show xs

with the explicit signature for 'concat'. We can now type
"serialize1 getP" at the GHCi prompt and get the desired result.



More information about the Generics mailing list