Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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. Re: lens-aeson and error messages (Alexey Shmalko)
2. Re: Packages (Karl Voelker)
----------------------------------------------------------------------
Message: 1
Date: Fri, 12 Jun 2015 09:28:16 +0300
From: Alexey Shmalko <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] lens-aeson and error messages
Message-ID:
<CAFC2PC42zgQ4irrs3ZnEQqpo7W46kZ=ww-l6t9icgc9j_um...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hi, Thomas!
I would come with implementation similar to this:
instance FromJSON Row where
parseJSON = withArray "Row" $ \ a ->
case Vector.length a of
3 ->
Row <$> parseJSON (a ! 0)
<*> parseJSON (a ! 1)
<*> parseJSON (a ! 2)
_ -> fail "Invalid Row."
Hope this helps.
On Fri, Jun 12, 2015 at 7:11 AM, Thomas Koster <[email protected]> wrote:
> Hi list,
>
> tl;dr - I am using aeson and have an unusual JSON data structure to
> parse, so I have implemented the parseJSON function using the prisms
> and traversals in the lens-aeson package. Unfortunately, the only error
> message I ever get from my parser is "mempty". How can my parser give
> better error messages when using lens-aeson?
>
> Consider a need to implement parseJSON for the following type.
>
> data Row = Row [Text] Int Text
>
> The twist is that the values are in a JSON list, not an object.
>
> [["a","b","c"], 4, "a title"]
>
> The JSON above should be decoded to the following Haskell value.
>
> Row ["a", "b", "c"] 4 "a title"
>
> My first FromJSON instance was naive.
>
> instance FromJSON Row where
> parseJSON = withArray "Row" $ \ a ->
> case Vector.toList a of
> (x : y : z : []) ->
> Row <$> parseJSON x
> <*> parseJSON y
> <*> parseJSON z
> _ -> fail "Invalid Row."
>
> Then I decided that pattern matching a vector like that via an
> intermediate list was probably rookie stuff, so I tried lenses (this is
> my first attempt at lenses, btw).
>
> instance FromJSON Row where
> parseJSON v =
> Row <$> (v ^. nth 0 . to parseJSON)
> <*> (v ^. nth 1 . to parseJSON)
> <*> (v ^. nth 2 . to parseJSON)
>
> This looks like it works but now the only error message I get is
> "mempty". I think this is because the lens operators are folding with
> the Monoid Parser instance where mempty = fail "mempty".
>
> Can I continue to use lenses but produce better error messages? If so,
> how? The lens package haddocks baffle me.
>
> Any suggestions to improve my use of lenses are also welcome (e.g. the
> expression "to parseJSON" seems so useful that I thought it might be
> named in the lens-aeson package. But it isn't, so its absence makes me
> suspect that I'm using it incorrectly).
>
> Alternative, non-lens-based suggestions for de-constructing a Vector,
> pattern matching its elements, without too many intermediate lists or
> tuples are also welcome.
>
> Thanks in advance.
>
> --
> Thomas Koster
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Sat, 13 Jun 2015 16:44:45 -0700
From: Karl Voelker <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Packages
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
If your library has any internal modules, make sure to list them in the
other-modules section of your cabal file. Every module has to be listed
somewhere in the cabal file; otherwise, cabal will not include that
module's source file in the tarball that can be built with the "cabal
sdist" command.
In other words, a more thorough test for package completeness is to run
"cabal sdist," take the tarball somewhere else, extract it, and build
from that.
-Karl
On Thu, Jun 11, 2015, at 02:05 AM, Mike Houghton wrote:
> Thank you.
>
> > On 11 Jun 2015, at 09:46, Sumit Sahrawat, Maths & Computing, IIT (BHU)
> > <[email protected]> wrote:
> >
> > Your .cabal file will have some exported-modules. Install the library using
> > `cabal install` and then import these modules to test them.
> >
> > Take a look here for more: https://www.haskell.org/cabal/users-guide/
> >
> > On 11 June 2015 at 13:51, Mike Houghton <[email protected]> wrote:
> > I?m using Cabal to build a package from some source I?m writing. It is not
> > an executable but rather a library.
> > How can I test locally that the package I?m making is complete? ie How do I
> > reference the package I?ve just buiilt in a haskell source file?
> >
> >
> > Thanks
> > Mike
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
> >
> >
> > --
> > Regards
> >
> > Sumit Sahrawat
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 84, Issue 22
*****************************************