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. Use Lens to manipulate Data.Tree (Zach Moazeni)
2. Re: Use Lens to manipulate Data.Tree (Zach Moazeni)
3. Re: Record types with multiple constructors (Magnus Therning)
4. Solution to problem 17 (99 Haskell problems)? (jean lopes)
5. Support for PostgreSQL array types (Riaan)
----------------------------------------------------------------------
Message: 1
Date: Sun, 7 Dec 2014 11:08:01 -0500
From: Zach Moazeni <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Use Lens to manipulate Data.Tree
Message-ID:
<CA+60NJ5W_gmmx4uRuPH=7y+udmyw7_wnoknvbxexpdbc9ct...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello,
I'm trying to understand how I would manipulate a Data.Tree in Haskell. I
came across this StackOverflow answer and accompanying blog post, but it
doesn't run locally for me:
* http://stackoverflow.com/a/15489761/410759
* https://www.fpcomplete.com/user/davorak/code-snippets/zipper-tree-examples
Here's a gist with the code and the error I'm seeing:
https://gist.github.com/zmoazeni/0049f3ab365ae600b131
I just want to start slow and be able to do three actions:
* add +10 to all values in the tree
* add a node to an existing node's subForest
* remove a node (along with its subForest) from the tree
I understand that this won't actually "edit in place" and my code would
need to call a function which would return an updated version of the
original tree.
Finally, Lens wasn't my first choice. I was trying to understand Zippers
from http://learnyouahaskell.com/zippers and my brain seized. I'm just
falling back to Lens because it seems like the simplest/dsl-ish way to
manipulate structures like this.
Thanks for any help!
-Zach
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141207/8b5d3031/attachment-0001.html>
------------------------------
Message: 2
Date: Sun, 7 Dec 2014 14:17:33 -0500
From: Zach Moazeni <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Use Lens to manipulate Data.Tree
Message-ID:
<CA+60NJ5KmjbOC8xi4UAOHcrHdS4DOgjRf=j50bjuicqcoke...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
The folks in the #haskell-lens irc channel helped me out. Installing and
importing http://hackage.haskell.org/package/zippers fixed my problem.
Sounds like it was split out of the lens package at some point.
-Zach
On Sun, Dec 7, 2014 at 11:08 AM, Zach Moazeni <[email protected]> wrote:
> Hello,
>
> I'm trying to understand how I would manipulate a Data.Tree in Haskell. I
> came across this StackOverflow answer and accompanying blog post, but it
> doesn't run locally for me:
>
> * http://stackoverflow.com/a/15489761/410759
> *
> https://www.fpcomplete.com/user/davorak/code-snippets/zipper-tree-examples
>
> Here's a gist with the code and the error I'm seeing:
> https://gist.github.com/zmoazeni/0049f3ab365ae600b131
>
> I just want to start slow and be able to do three actions:
>
> * add +10 to all values in the tree
> * add a node to an existing node's subForest
> * remove a node (along with its subForest) from the tree
>
> I understand that this won't actually "edit in place" and my code would
> need to call a function which would return an updated version of the
> original tree.
>
> Finally, Lens wasn't my first choice. I was trying to understand Zippers
> from http://learnyouahaskell.com/zippers and my brain seized. I'm just
> falling back to Lens because it seems like the simplest/dsl-ish way to
> manipulate structures like this.
>
> Thanks for any help!
> -Zach
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141207/ebe39ed0/attachment-0001.html>
------------------------------
Message: 3
Date: Sun, 7 Dec 2014 22:55:22 +0100
From: Magnus Therning <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Record types with multiple
constructors
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Sun, Dec 07, 2014 at 09:37:11AM +0000, Derek McLoughlin wrote:
> Hi,
>
> Record types usually have a single constructor. I've even seen blog
> posts that suggest that they must have a single constructor. However,
> multiple constructors are allowed:
>
> data Employee = RegularEmployee {
> name :: String
> } |
> Supervisor {
> name :: String,
> salesTarget :: Double
> }
> Manager {
> name :: String,
> salesTarget :: Double
> budget :: Double
> }
>
> I don't see this used much in Haskell code - either in explanatory
> books/tutorials or in code I've examined on GitHub. Are there
> drawbacks to using multiple constructors in this way?
I think you might see it fairly frequently in users of command line
parser libs, e.g. optparse-applicative[^1], for accepting
sub-commands.
/M
[^1]: http://hackage.haskell.org/package/optparse-applicative
--
Magnus Therning OpenPGP: 0xAB4DFBA4
email: [email protected] jabber: [email protected]
twitter: magthe http://therning.org/magnus
Perl is another example of filling a tiny, short-term need, and then
being a real problem in the longer term.
-- Alan Kay
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141207/6ea86e09/attachment-0001.sig>
------------------------------
Message: 4
Date: Mon, 8 Dec 2014 08:17:32 -0200
From: jean lopes <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Solution to problem 17 (99 Haskell
problems)?
Message-ID:
<cakeoksiqntphj7zclmjcxxw9ptby0zx_b19xiionvvxxhfv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello, I am wondering, is this solution acceptable to the question 17 ? (
https://www.haskell.org/haskellwiki/99_questions/11_to_20)
code:
split :: [a] -> Int -> ([a], [a])
split xs y = fst (mapAccumL (\a b -> (let f = fst a
s = snd a
l = length f
in if l < y
then (f ++ [b], s)
else (f, s ++ [b]), b)) ([],[])
xs)
Also, any inputs are welcome (indentation, misuse of something)
Best regards,
Jean Lopes
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141208/742b1396/attachment-0001.html>
------------------------------
Message: 5
Date: Mon, 8 Dec 2014 21:34:07 +1100
From: Riaan <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Support for PostgreSQL array types
Message-ID:
<caghwpqrjog6nlvlkazcyys2b81q2ws6xuxf6qxtcw2412eq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
This is a question about database query libraries. I am trying to do some
analytics on a Postgresql database and up to now have been using
Database.HDBC for most of my querying.
One of the columns on the database is a two dimensional float8 array. I
tried using Database.PostgreSQL.Simple but got stuck on this array as I
could not figure out how to extend the built in conversion functions to
cater for something like this. So went back to HDBC. But now my queries
are starting to get fairly long and I have been looking at libraries like
Persistent with Esqualeto, HaskellDB and Groundhog to make my queries a
little more composable and type safe.
However I have not been able to find any examples of any of these libraries
using postgres arrays and given my postgresql-simple experience I worried
that I might similarly be unable, because of my low level of haskell
ability, to extend the conversion functions.
So to my question. Does anyone have experience with one of these libraries
in dealing with postgresql arrays and could someone perhaps send me a
simple example that I could use as a basis. Failing that, can anyone
advise me on which of these libraries have the most haskell newbie (LYAH
trained, but still struggling with RWH) friendly approach to writing new
conversion functions?
Thanks
Riaan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141208/1b0b2d8c/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 78, Issue 3
****************************************