[Haskell-beginners] aeson json paring

Raphaël Mongeau raphaelsimeon at gmail.com
Fri Sep 26 14:41:35 UTC 2014


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 <miroslav.karpis at gmail.com>:

> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Viva Cila
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140926/0f8002eb/attachment.html>


More information about the Beginners mailing list