
*Andrew Coppin wrote: * | I'm trying to construct a function | | all_trees :: [Int] -> [Tree] | | such that all_trees [1,2,3] will yield : If you write a helper function that takes an N element list, and returns all 2^N ways of dividing those elements into 2 lists, e.g. splits "ab" --> [("ab",""),("b","a"),("a","b"),("","ab")] then you can use it both for dividing the initial list into kept and discarded elements, and for dividing a list between a left subtree and a right subtree. Regards, Tom

On Thu, 14 Jun 2007, Tom Pledger wrote:
*Andrew Coppin wrote: *
| I'm trying to construct a function | | all_trees :: [Int] -> [Tree] | | such that all_trees [1,2,3] will yield :
If you write a helper function that takes an N element list, and returns all 2^N ways of dividing those elements into 2 lists, e.g.
splits "ab" --> [("ab",""),("b","a"),("a","b"),("","ab")]
then you can use it both for dividing the initial list into kept and discarded elements, and for dividing a list between a left subtree and a right subtree.
This one was discussed recently: http://www.haskell.org/pipermail/haskell-cafe/2007-May/025767.html
participants (2)
-
Henning Thielemann
-
Tom Pledger