[Haskell-cafe] Construct all possible trees

Tom Pledger tom at pledger.gen.nz
Wed Jun 13 08:10:08 EDT 2007

*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.


More information about the Haskell-Cafe mailing list