Re: [Haskell-cafe] Re: Construct all possible trees

2007-06-14 Thread Mirko Rahn
Jon Fairbairn wrote: Trees with all the elements of a list in that order: the_trees [x] = [Leaf x] the_trees l = zipWith Branch (concat (map the_trees (tail $ inits l))) (concat (map the_trees (tail $ tails l))) Sorry, but this problem seems to trigger incorrect

[Haskell-cafe] Re: Construct all possible trees

2007-06-14 Thread Jon Fairbairn
Mirko Rahn [EMAIL PROTECTED] writes: Jon Fairbairn wrote: Trees with all the elements of a list in that order: the_trees [x] = [Leaf x] the_trees l = zipWith Branch (concat (map the_trees (tail $ inits l))) (concat (map the_trees (tail $ tails l))) Sorry,

[Haskell-cafe] Re: Construct all possible trees

2007-06-13 Thread apfelmus
Andrew Coppin wrote: I'm trying to construct a function all_trees :: [Int] - [Tree] such that all_trees [1,2,3] will yield [ Leaf 1, Leaf 2, Leaf 3, Branch (Leaf 1) (Leaf 2), Branch (Leaf 1) (Leaf 3), Branch (Leaf 2) (Leaf 1), Branch (Leaf 2) (Leaf 3), Branch (Leaf 3) (Leaf 1),

Re: [Haskell-cafe] Re: Construct all possible trees

2007-06-13 Thread Mirko Rahn
apfelmus wrote: Explanation and the code: import Data.List import Control.Applicative import qualified Data.Foldable as Foldable import Data.Traversable as Traversable import Control.Monad.State data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving (Show)

[Haskell-cafe] Re: Construct all possible trees

2007-06-13 Thread apfelmus
Mirko Rahn wrote: apfelmus wrote: data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving (Show) permTrees xs = concat . takeWhile (not . null) . map (flip evalStateT xs . Traversable.sequence) $ trees select where select = StateT $ \xs -

Re: [Haskell-cafe] Re: Construct all possible trees

2007-06-13 Thread Andrew Coppin
Jon Fairbairn wrote: I'm trying to construct a function all_trees :: [Int] - [Tree] such that all_trees [1,2,3] will yield [ Leaf 1, Leaf 2, Leaf 3, Branch (Leaf 1) (Leaf 2), Branch (Leaf 1) (Leaf 3), Branch (Leaf 2) (Leaf 1), Branch (Leaf 2) (Leaf 3), Branch (Leaf 3) (Leaf 1), Branch (Leaf

[Haskell-cafe] Re: Construct all possible trees

2007-06-13 Thread Jon Fairbairn
Andrew Coppin [EMAIL PROTECTED] writes: Jon Fairbairn wrote: I'm trying to construct a function all_trees :: [Int] - [Tree] such that all_trees [1,2,3] will yield [ Leaf 1, Leaf 2, Leaf 3, Branch (Leaf 1) (Leaf 2), Branch (Leaf 1) (Leaf 3), Branch (Leaf 2) (Leaf 1),

[Haskell-cafe] Re: Construct all possible trees

2007-06-12 Thread Jon Fairbairn
Andrew Coppin [EMAIL PROTECTED] writes: I'm trying to construct a function all_trees :: [Int] - [Tree] such that all_trees [1,2,3] will yield [ Leaf 1, Leaf 2, Leaf 3, Branch (Leaf 1) (Leaf 2), Branch (Leaf 1) (Leaf 3), Branch (Leaf 2) (Leaf 1), Branch (Leaf 2) (Leaf 3),