
Hi, I'm trying to run an example from the eason documentation https://hackage.haskell.org/package/aeson-0.6.1.0/docs/Data-Aeson.html#g:3 : λ> do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2)) I made a function: jsonTest = do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2)) which can not compile: hh.hs:35:41: No instance for (Show a0) arising from a use of ‘show’ The type variable ‘a0’ is ambiguous .... ... Please what am I doing wrong? Cheers, Miro

The key here is "The type variable ‘a0’ is ambiguous".
You need to add a type signature to age so the compiler know if age is of
type In,Float or Double ...
:)
2014-09-26 10:34 GMT-04:00 Miro Karpis
Hi, I'm trying to run an example from the eason documentation https://hackage.haskell.org/package/aeson-0.6.1.0/docs/Data-Aeson.html#g:3 :
λ> do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2))
I made a function:
jsonTest = do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2))
which can not compile: hh.hs:35:41: No instance for (Show a0) arising from a use of ‘show’ The type variable ‘a0’ is ambiguous .... ...
Please what am I doing wrong?
Cheers, Miro
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Viva Cila

On 09/26/2014 03:34 PM, Miro Karpis wrote:
Hi, I'm trying to run an example from the eason documentation https://hackage.haskell.org/package/aeson-0.6.1.0/docs/Data-Aeson.html#g:3 :
λ> do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2))
I made a function:
jsonTest = do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2))
which can not compile: hh.hs:35:41: No instance for (Show a0) arising from a use of ‘show’ The type variable ‘a0’ is ambiguous .... ...
Please what am I doing wrong?
Cheers, Miro
As pointed out in the other response, you'll need a type signature somewhere to indicate what type your ‘age’ should be. I'd like to point out something else however. You appear to be using hard tabs (‘\t’ character): please don't do this! Haskell is alignment-sensitive and you'll run into problems due to this unless you *very* strictly only insert tabs. FTR GHC treats one \t as 8 spaces. There are beginners on daily basis in #haskell wondering why their code doesn't compile just to discover tabs once they share it through lpaste.net or similar service. [1] is the standard reference for style, especially see the ‘Tabs’ section. So, please, set your editor to only insert spaces. [1]: http://urchin.earth.li/~ian/style/haskell.html -- Mateusz K.
participants (3)
-
Mateusz Kowalczyk
-
Miro Karpis
-
Raphaël Mongeau