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. partition a list in all possible ways (I. J. Kennedy)
2. Re: partition a list in all possible ways (Bryce Verdier)
3. Re: partition a list in all possible ways (Daniel Fischer)
4. Good reads? (Christopher Svanefalk)
----------------------------------------------------------------------
Message: 1
Date: Tue, 26 Apr 2011 13:10:37 -0500
From: "I. J. Kennedy" <[email protected]>
Subject: [Haskell-beginners] partition a list in all possible ways
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
I'm looking for a function [a] -> [[[a]]] that will partition a list into
non-empty pieces in all possible ways.
For example
f [1,2,3,4] = [[[1],[2],[3],[4]], [[1],[2],[3,4]], [[1],[2,3],[4]],
[[1],[2,3,4]], [[1,2],[3],[4]], [[1,2],[3,4]], [[1,2,3],[4]], [[1,2,3,4]]]
Perhaps this is a well-known function to experts, but not to me. Hoogle
doesn't seem to have anything with this signature.
Thanks,
Jack
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110426/e29bab9b/attachment-0001.htm>
------------------------------
Message: 2
Date: Tue, 26 Apr 2011 11:34:19 -0700
From: Bryce Verdier <[email protected]>
Subject: Re: [Haskell-beginners] partition a list in all possible ways
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Take a look at Data.List and the function subsequences.
http://www.haskell.org/ghc/docs/7.0.2/html/libraries/base-4.3.1.0/Data-List.html#v:subsequences
The only thing you'll need to figure out after that is how to transform
all of those strings to a list data type.
I hope this helps,
Bryce
On 04/26/2011 11:10 AM, I. J. Kennedy wrote:
> I'm looking for a function [a] -> [[[a]]] that will partition a list
> into non-empty pieces in all possible ways.
> For example
> f [1,2,3,4] = [[[1],[2],[3],[4]], [[1],[2],[3,4]], [[1],[2,3],[4]],
> [[1],[2,3,4]], [[1,2],[3],[4]], [[1,2],[3,4]], [[1,2,3],[4]], [[1,2,3,4]]]
> Perhaps this is a well-known function to experts, but not to me.
> Hoogle doesn't seem to have anything with this signature.
> Thanks,
> Jack
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110426/a938089c/attachment-0001.htm>
------------------------------
Message: 3
Date: Tue, 26 Apr 2011 20:50:03 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] partition a list in all possible ways
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
On Tuesday 26 April 2011 20:10:37, I. J. Kennedy wrote:
> I'm looking for a function [a] -> [[[a]]] that will partition a list
> into non-empty pieces in all possible ways.
> For example
> f [1,2,3,4] = [[[1],[2],[3],[4]], [[1],[2],[3,4]], [[1],[2,3],[4]],
> [[1],[2,3,4]], [[1,2],[3],[4]], [[1,2],[3,4]], [[1,2,3],[4]],
> [[1,2,3,4]]]
Your description doesn't quite match your example, [[1,3],[2],[4]] is a
partition of [1,2,3,4] into non-empty pieces which doesn't appear in your
result.
By your example, you want all possible partitions into non-empty contiguous
subsequences, which is somewhat easier (not that all partitions are really
difficult).
> Perhaps this is a well-known function to experts, but not
> to me. Hoogle doesn't seem to have anything with this signature.
> Thanks,
> Jack
Think recursively. For (x:xs), you get two classes of partitions,
a) those where x makes up a part of its own, those are
[[x]:parts | parts <- partitions xs]
or map ([x] :) (partitions xs)
b) those where x belongs to the same part as its successor in the original
list, those are obtained by sticking x to the front of each first part of
the partitions of xs,
[(x:ys):yss | (ys:yss) <- partitions xs]
For an empty list, you get exactly one partition into non-empty pieces, the
empty partition, [ [] ], so
partitions [] = [[]]
partitions (x:xs) = [[x]:p | p <- partitions xs]
++ [(x:ys):yss | (ys:yss) <- partitions xs]
------------------------------
Message: 4
Date: Tue, 26 Apr 2011 21:51:44 +0200
From: Christopher Svanefalk <[email protected]>
Subject: [Haskell-beginners] Good reads?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hey all,
I have mostly been brought in imperative/OOP languages. In connection
with my college studies, however, I have taken great interest in the
functional paradigm, and would very much like to dig deeper into it.
I am currently reading through Peyton-Jones "Haskell: The Craft of
Functional Programming" (2nd ed.), as well as a great paper published by
one of my professors
(http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html). However, what
other works, in your opinions, should I look into to get a more complete
understanding of functional programming?
Thanks in advance!
Chris
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 34, Issue 37
*****************************************