<div dir="ltr"><div><div><div><div><div><div><div><div>Hello,<br><br></div> I'm again a bit stuck on a simple problem, and I think it'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't get yet about "data" versus "type".<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 -> 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> <--- 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 \"object\" (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't match expected type `Map.Map T.Text Value'<br> with actual type `Object'<br> In the first argument of `parseConfigMap', namely `map'<br> In the second argument of `($)', namely `parseConfigMap map'<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 "Map Text Value"...<br>
<br></div>Any hint? And that really doesn't look like a good idea to me to define a type and a data by the same name, but it's apparently the right way to do it...<br><br></div><div>Thank you!<br></div><div><br></div>
Emmanuel<br></div>