Oleg,<br><br>Ok that looks like exactly what I&#39;m looking for :-)<br><br>Unfortunately I cant seem to run it.&nbsp; It comes up with strange typing messages when compiling:<br><br>*TestDeserialize&gt; serialize P<br><br>&lt;interactive&gt;:1:0:
<br>&nbsp;&nbsp;&nbsp; No instance for (LDat (TL_red [a])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (HCons (Int -&gt; [String])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (HCons (Float -&gt; [String]) (HCons (String -&gt; [S<br>tring]) HNil)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (String -&gt; String -&gt; Person)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; df)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from use of `serialize&#39; at &lt;interactive&gt;:1:0-10<br>&nbsp;&nbsp;&nbsp; Possible fix:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add an instance declaration for<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LDat (TL_red [a])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (HCons (Int -&gt; [String])
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (HCons (Float -&gt; [String]) (HCons (String -&gt; [String]) HNil))<br>)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (String -&gt; String -&gt; Person)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; df)<br>&nbsp;&nbsp;&nbsp; In the expression: serialize P<br>&nbsp;&nbsp;&nbsp; In the definition of `it&#39;: it = serialize P
<br><br>where P is:<br><br>getP = P &quot;Lammel&quot; &quot;Amsterdam&quot;<br><br>(for simplicity)<br><br>Similar looking errors with genCom, and/or with deserialize.<br><br>I guess I need to add an instance or deriving statement to the P class?
<br><br>On another track, read through SYB3 a little, and it seems to have a really clean way to create polymorphic functions, such as:<br><br>class Data a =&gt; StringParser a where<br>&nbsp;&nbsp; parsestring :: String -&gt; a<br>
&nbsp;&nbsp; parsestring x = fst $ head $gread(x)<br>instance StringParser Int where<br>&nbsp;&nbsp; parsestring x = read x<br>instance StringParser String where<br>&nbsp;&nbsp; parsestring x = read( &quot;\&quot;&quot; ++ x ++ &quot;\&quot;&quot; )<br>
<br>Looks like it should do exactly what I need: take a string and create any data type, as long as the data type is an instance of Data.<br><br>Unfortunately, and strangely(?), it only seems to work for datatypes declared as instance.&nbsp; That&#39;s surprising since the default function in the class declaration works for the Data class.&nbsp; It would make sense if the default function would be applied to all data types which are instances of the base classes?
<br><br>So, that didnt work yet.<br><br><br>A normal &quot;read&quot; ought to work, but there&#39;s no way of declaring that the children of the parent data type are instances of Read, so it works straight away less well (gets caught by the compiler).
<br><br><br>The only return functions which build so far are:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return&nbsp; (fromJust $ fst $ head $ gread( &quot;(&quot; ++ (fromJust value) ++ &quot;)&quot; ) )<br>and:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ((fromJust . cast) value)<br><br>
... but neither of these work particularly well at runtime, and they&#39;re difficult to customize for different data types.<br><br><br>I really like the SYB3 approach to creating customizable generic functions, but it&#39;s a shame that there&#39;s no way of declaring a default function that works for all instances of the base classe(s).&nbsp; Or maybe I just didnt find out how to do that yet?
<br><br>