
Hello, I'm again a bit stuck on a simple problem, and I think it's the same problem that I faced some time ago: http://comments.gmane.org/gmane.comp.lang.haskell.beginners/10843 There is obviously something that I didn't get yet about "data" versus "type". 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. Now we have: data Value = Object Object <--- the case I hope for | Array Array | String Text | Number Number | Bool !Bool | Null deriving (Eq, Show, Typeable, Data) And then: -- | A JSON \"object\" (key\/value map).type Object = Map Text Value 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: question.hs:12:62: Couldn't match expected type `Map.Map T.Text Value' with actual type `Object' In the first argument of `parseConfigMap', namely `map' In the second argument of `($)', namely `parseConfigMap map' In the expression: return $ parseConfigMap map 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"... 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... Thank you! Emmanuel

Hi there.
-- | A JSON \"object\" (key\/value map). type Object = Map Text Value
See https://github.com/bos/aeson/blob/master/release-notes.markdown Quoting: " 0.3 to 0.4 [...] We switched the intermediate representation of JSON objects from Data.Map to Data.HashMap, which has improved type conversion performance. "
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:
question.hs:12:62: Couldn't match expected type `Map.Map T.Text Value' with actual type `Object' In the first argument of `parseConfigMap', namely `map' In the second argument of `($)', namely `parseConfigMap map' In the expression: return $ parseConfigMap map
This has nothing to do with "type" vs. "data". The type synonym expansion of Object doesn't match your type, because it uses a HashMap rather than a Map. Cheers, Andres -- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com

Hi,
thank you for the tip! It helps but it's not quite there yet. If you see
the program in attachment, I can make it compile only by commenting the
type declaration for the second function, otherwise it's the exact same
error message as before.
In -Wall the compiler does suggest me the signature, but it's not
enlightening for me at this point, I've yet to dig that deep in haskell's
type system:
parseConfigMap :: forall t (m :: * -> *). Monad m => t -> m ()
Can you explain me why my type signature is not correct?
Thank you again!
Emmanuel
On Sun, Mar 17, 2013 at 1:23 PM, Andres Löh
Hi there.
-- | A JSON \"object\" (key\/value map). type Object = Map Text Value
See https://github.com/bos/aeson/blob/master/release-notes.markdown
Quoting:
" 0.3 to 0.4
[...]
We switched the intermediate representation of JSON objects from Data.Map to Data.HashMap, which has improved type conversion performance. "
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:
question.hs:12:62: Couldn't match expected type `Map.Map T.Text Value' with actual type `Object' In the first argument of `parseConfigMap', namely `map' In the second argument of `($)', namely `parseConfigMap map' In the expression: return $ parseConfigMap map
This has nothing to do with "type" vs. "data". The type synonym expansion of Object doesn't match your type, because it uses a HashMap rather than a Map.
Cheers, Andres
-- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hi again.
thank you for the tip! It helps but it's not quite there yet. If you see the program in attachment, I can make it compile only by commenting the type declaration for the second function, otherwise it's the exact same error message as before.
You're probably using the wrong HashMap. There are several packages on Hackage implementing similarly-named data structures (which is confusing, I know, but such is life in a decentralized and open world). You should use what aeson is using (because that's the library defining the Object type synonym). Looking at the import list of http://hackage.haskell.org/packages/archive/aeson/0.6.0.2/doc/html/src/Data-... we see import Data.HashMap.Strict (HashMap) and by checking the package dependencies of aeson, we figure out that this module is provided by the unordered-containers package. Cheers, Andres -- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com

Thank you, that was the trick! It would be handy it there was a way through
the online hackage packages pages to click through the dependencies. I
guess you checked the .cabal by hand or used some slightly more arcane
cabal commands to get that information.
Thank you again and nice rest of week-end!
Emmanuel
On Sun, Mar 17, 2013 at 2:51 PM, Andres Löh
Hi again.
thank you for the tip! It helps but it's not quite there yet. If you see the program in attachment, I can make it compile only by commenting the type declaration for the second function, otherwise it's the exact same error message as before.
You're probably using the wrong HashMap. There are several packages on Hackage implementing similarly-named data structures (which is confusing, I know, but such is life in a decentralized and open world). You should use what aeson is using (because that's the library defining the Object type synonym).
Looking at the import list of
http://hackage.haskell.org/packages/archive/aeson/0.6.0.2/doc/html/src/Data-...
we see
import Data.HashMap.Strict (HashMap)
and by checking the package dependencies of aeson, we figure out that this module is provided by the unordered-containers package.
Cheers, Andres
-- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

If you hover over "type Object = HashMap Text Value" in
Data.Aeson.Types in hackage, you will see that the HashMap link links
to http://hackage.haskell.org/packages/archive/unordered-containers/0.2.3.0/doc...,
which tells you what package it came from and what to import.
On Sun, Mar 17, 2013 at 11:16 AM, Emmanuel Touzery
Thank you, that was the trick! It would be handy it there was a way through the online hackage packages pages to click through the dependencies. I guess you checked the .cabal by hand or used some slightly more arcane cabal commands to get that information.
Thank you again and nice rest of week-end!
Emmanuel
On Sun, Mar 17, 2013 at 2:51 PM, Andres Löh
wrote: Hi again.
thank you for the tip! It helps but it's not quite there yet. If you see the program in attachment, I can make it compile only by commenting the type declaration for the second function, otherwise it's the exact same error message as before.
You're probably using the wrong HashMap. There are several packages on Hackage implementing similarly-named data structures (which is confusing, I know, but such is life in a decentralized and open world). You should use what aeson is using (because that's the library defining the Object type synonym).
Looking at the import list of
http://hackage.haskell.org/packages/archive/aeson/0.6.0.2/doc/html/src/Data-...
we see
import Data.HashMap.Strict (HashMap)
and by checking the package dependencies of aeson, we figure out that this module is provided by the unordered-containers package.
Cheers, Andres
-- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Yes, you are right thank you. I don't know how could I miss it...
emmanuel
On Sun, Mar 17, 2013 at 4:25 PM, David McBride
If you hover over "type Object = HashMap Text Value" in Data.Aeson.Types in hackage, you will see that the HashMap link links to http://hackage.haskell.org/packages/archive/unordered-containers/0.2.3.0/doc... , which tells you what package it came from and what to import.
Thank you, that was the trick! It would be handy it there was a way
the online hackage packages pages to click through the dependencies. I guess you checked the .cabal by hand or used some slightly more arcane cabal commands to get that information.
Thank you again and nice rest of week-end!
Emmanuel
On Sun, Mar 17, 2013 at 2:51 PM, Andres Löh
wrote: Hi again.
thank you for the tip! It helps but it's not quite there yet. If you see the program in attachment, I can make it compile only by commenting
On Sun, Mar 17, 2013 at 11:16 AM, Emmanuel Touzery
wrote: through the type declaration for the second function, otherwise it's the exact same error message as before.
You're probably using the wrong HashMap. There are several packages on Hackage implementing similarly-named data structures (which is confusing, I know, but such is life in a decentralized and open world). You should use what aeson is using (because that's the library defining the Object type synonym).
Looking at the import list of
http://hackage.haskell.org/packages/archive/aeson/0.6.0.2/doc/html/src/Data-...
we see
import Data.HashMap.Strict (HashMap)
and by checking the package dependencies of aeson, we figure out that this module is provided by the unordered-containers package.
Cheers, Andres
-- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Sun, Mar 17, 2013 at 8:55 PM, David McBride
If you hover over "type Object = HashMap Text Value" in Data.Aeson.Types in hackage, you will see that the HashMap link links to http://hackage.haskell.org/packages/archive/unordered-containers/0.2.3.0/doc... , which tells you what package it came from and what to import.
Is there some hackage 'hover-click' help/tut somewhere? Maybe 10 years of python habits... I find hackage often hard to navigate

On 03/21/2013 08:31 PM, Rustom Mody wrote:
On Sun, Mar 17, 2013 at 8:55 PM, David McBride
mailto:toad3k@gmail.com> wrote: If you hover over "type Object = HashMap Text Value" in Data.Aeson.Types in hackage, you will see that the HashMap link links to http://hackage.haskell.org/packages/archive/unordered-containers/0.2.3.0/doc..., which tells you what package it came from and what to import.
Is there some hackage 'hover-click' help/tut somewhere? Maybe 10 years of python habits... I find hackage often hard to navigate
All Hackage links point to the module that the function or type came from, even if it is from a different package. You can use this to find out which package something comes from. This can be useful if you need to import a type which is not from the same package as the one you are currently browsing. You just click the link and see which package it takes you to. There are two ways to tell which package you are currently browsing: * Fastest way: Just look at the url. The part after the "/archive/" is the package name. * Most user-friendly way: Click the 'Contents' link in the upper-right-hand corner. That takes you to the home page of the package you are currently browsing, which will display all the metadata about that page.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (5)
-
Andres Löh
-
David McBride
-
Emmanuel Touzery
-
Gabriel Gonzalez
-
Rustom Mody