<div dir="ltr">Thank you guys.<div><br></div><div style>I cannot use a explicit type for there are quite a few of them. But from MigMit, I understand why my original cannot work.</div></div><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Sat, Jun 22, 2013 at 4:46 AM, Vincent Ambo <span dir="ltr">&lt;<a href="mailto:tazjin@gmail.com" target="_blank">tazjin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Is there a reason why you can&#39;t use an explicit type variable?<div><br></div><div><div><font face="courier new, monospace">{-# LANGUAGE OverloadedStrings, ExistentialQuantification #-}</font></div><div>
<font face="courier new, monospace"><br>

</font></div><div><font face="courier new, monospace">import Data.Aeson</font></div><div><font face="courier new, monospace">import Control.Applicative</font></div><div><font face="courier new, monospace">import Control.Monad (mzero)</font></div>


<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">data ActionData j</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap">        </span>= (FromJSON j, ToJSON j) =&gt; AD j j</font></div>


<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">instance ToJSON (ActionData j) where</font></div><div class="im"><div><font face="courier new, monospace">  toJSON (AD o n) = object [ &quot;oldData&quot; .= o</font></div>


<div><font face="courier new, monospace">                           , &quot;newData&quot; .= n ]</font></div><div><font face="courier new, monospace"><br></font></div></div><div><font face="courier new, monospace">instance (ToJSON j, FromJSON j) =&gt; FromJSON (ActionData j) where</font></div>
<div class="im">

<div><font face="courier new, monospace">  parseJSON (Object v) = AD</font></div><div><font face="courier new, monospace">    &lt;$&gt; v .: &quot;oldData&quot;</font></div><div><font face="courier new, monospace">    &lt;*&gt; v .: &quot;newData&quot;</font></div>


<div><font face="courier new, monospace">  parseJSON _ = mzero</font></div></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/6/21 Miguel Mitrofanov <span dir="ltr">&lt;<a href="mailto:miguelimo38@yandex.ru" target="_blank">miguelimo38@yandex.ru</a>&gt;</span><br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Forgot to reply all, as usual.<br>
<br>
-------- Пересылаемое сообщение  --------<br>
21.06.2013, 12:52, &quot;Miguel Mitrofanov&quot; &lt;<a href="mailto:miguelimo38@yandex.ru" target="_blank">miguelimo38@yandex.ru</a>&gt;:<br>
<br>
Actually, this is not the real error you should care about. Try removing FromJSON instance completely, and you&#39;ll get a lot more. And these are fundamental: you have to decide what &quot;j&quot; to use when serializing. Haskell won&#39;t automagically substitute some suitable type for you.<br>



<br>
So, that&#39;s a classic mismatch: for serializing (ToJSON) you need your &quot;j&quot; type to be known to the AD value (meaning: it should be quantified existentially), but for deserializing you need it to be any type (quantified universally).<br>



<br>
All in all, AD seems to be the wrong type.<br>
<br>
21.06.2013, 12:18, &quot;Magicloud Magiclouds&quot; &lt;<a href="mailto:magicloud.magiclouds@gmail.com" target="_blank">magicloud.magiclouds@gmail.com</a>&gt;:<br>
<div><div><br>
&gt;  data ActionData = AD { oldData :: (FromJSON j, ToJSON j) =&gt; j<br>
&gt;                       , newData :: (FromJSON j, ToJSON j) =&gt; j}<br>
&gt;  instance ToJSON ActionData where<br>
&gt;    toJSON (AD o n) = object [ &quot;oldData&quot; .= o<br>
&gt;                             , &quot;newData&quot; .= n ]<br>
&gt;  instance FromJSON ActionData where<br>
&gt;    parseJSON (Object v) = AD<br>
&gt;      &lt;$&gt; v .: &quot;oldData&quot;<br>
&gt;      &lt;*&gt; v .: &quot;newData&quot;<br>
&gt;    parseJSON _ = mzero<br>
&gt;<br>
&gt;  I got when compile:<br>
&gt;      No instance for (FromJSON (forall j. (FromJSON j, ToJSON j) =&gt; j))<br>
&gt;        arising from a use of `.:&#39;<br>
&gt;      Possible fix:<br>
&gt;        add an instance declaration for<br>
&gt;        (FromJSON (forall j. (FromJSON j, ToJSON j) =&gt; j))<br>
&gt;      In the second argument of `(&lt;$&gt;)&#39;, namely `v .: &quot;oldData&quot;&#39;<br>
&gt;      In the first argument of `(&lt;*&gt;)&#39;, namely `AD &lt;$&gt; v .: &quot;oldData&quot;&#39;<br>
&gt;      In the expression: AD &lt;$&gt; v .: &quot;oldData&quot; &lt;*&gt; v .: &quot;newData&quot;<br>
&gt;<br>
&gt;  --<br>
&gt;  竹密岂妨流水过<br>
&gt;  山高哪阻野云飞<br>
&gt;<br>
&gt;  And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.<br>
</div></div>&gt;  ,<br>
&gt;  _______________________________________________<br>
&gt;  Haskell-Cafe mailing list<br>
&gt;  <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
&gt;  <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
-------- Завершение пересылаемого сообщения --------<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>竹密岂妨流水过<br>山高哪阻野云飞<br><br>And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.
</div>