Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. aeson json paring (Miro Karpis)
2. Re: aeson json paring (Rapha?l Mongeau)
3. Re: aeson json paring (Mateusz Kowalczyk)
----------------------------------------------------------------------
Message: 1
Date: Fri, 26 Sep 2014 16:34:32 +0200
From: Miro Karpis <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] aeson json paring
Message-ID:
<CAJnnbxF_wrS=8azqfqxden4o7td98yuorhyv9r8+ewyatbk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140926/f1394940/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 26 Sep 2014 10:41:35 -0400
From: Rapha?l Mongeau <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] aeson json paring
Message-ID:
<CAMTQk-FavSr0rxcgTyNV0HhmCu5mDW4b7WiyW4+bZ5d=dvb...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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 <[email protected]>:
> 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
> [email protected]
> 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-0001.html>
------------------------------
Message: 3
Date: Sat, 27 Sep 2014 05:20:11 +0100
From: Mateusz Kowalczyk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] aeson json paring
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
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.
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 75, Issue 21
*****************************************