<div dir="ltr"><div><div><div><div><div><div><div><div>Hello,<br><br></div> I&#39;m again a bit stuck on a simple problem, and I think it&#39;s the same problem that I faced some time ago:<br><a href="http://comments.gmane.org/gmane.comp.lang.haskell.beginners/10843">http://comments.gmane.org/gmane.comp.lang.haskell.beginners/10843</a><br>
<br></div> There is obviously something that I didn&#39;t get yet about &quot;data&quot; versus &quot;type&quot;.<br><br></div> In the program in attachment, I want to parse a JSON file to a Value, then if that value is in fact a JSON object, I want to explore its hash member name -&gt; member value.<br>
<br></div> Now we have:<br><br><pre><span class="">data</span> <span class="">Value</span> <span class="">=</span> <span class="">Object</span> <span class="">Object</span> &lt;--- the case I hope for
<a name="line-187"></a>           <span class="">|</span> <span class="">Array</span> <span class="">Array</span>
<a name="line-188"></a>           <span class="">|</span> <span class="">String</span> <span class="">Text</span>
<a name="line-189"></a>           <span class="">|</span> <span class="">Number</span> <span class="">Number</span>
<a name="line-190"></a>           <span class="">|</span> <span class="">Bool</span> <span class="">!</span><span class="">Bool</span>
<a name="line-191"></a>           <span class="">|</span> <span class="">Null</span>
<a name="line-192"></a>             <span class="">deriving</span> <span class="">(</span><span class="">Eq</span><span class="">,</span> <span class="">Show</span><span class="">,</span> <span class="">Typeable</span><span class="">,</span> <span class="">Data</span><span class="">)</span></pre>
<br></div><div><br></div>And then:<br><br><pre><a name="line-179"></a><a name="Object"></a><span class="">-- | A JSON \&quot;object\&quot; (key\/value map).</span>
<a name="line-180"></a><a name="Object"></a><span class="">type</span> <span class="">Object</span> <span class="">=</span> <span class="">Map</span> <span class="">Text</span> <span class="">Value</span>
<a name="line-181"><br><br></a></pre>So my clearly flawed plan is to get the value, pattern mach it against (Object hash) and then work on the hash. However for the program in attachment, which I would expect to compile, I get this compile error:<br>
<br>question.hs:12:62:<br>    Couldn&#39;t match expected type `Map.Map T.Text Value&#39;<br>                with actual type `Object&#39;<br>    In the first argument of `parseConfigMap&#39;, namely `map&#39;<br>    In the second argument of `($)&#39;, namely `parseConfigMap map&#39;<br>
    In the expression: return $ parseConfigMap map<br><br></div>That confuses me, because if the error means by Object the data, then I understood nothing. However if the error means by Object the type, then I would expect it to work, since the type exactly means &quot;Map Text Value&quot;...<br>
<br></div>Any hint? And that really doesn&#39;t look like a good idea to me to define a type and a data by the same name, but it&#39;s apparently the right way to do it...<br><br></div><div>Thank you!<br></div><div><br></div>
Emmanuel<br></div>