[Haskell-beginners] Re: about the concatenation on a tree

Achim Schneider barsoap at web.de
Sun Jan 4 03:19:04 EST 2009

"Max cs" <max.cs.2009 at googlemail.com> wrote:

> hi all, not sure if there is someone still working during holiday
> like me : )
> I got a little problem in implementing some operations on tree.
> suppose we have a tree date type defined:
> data Tree a = Leaf a | Branch (Tree a) (Tree a)
> I want to do a concatenation on these tree just like the concat on
> list. Anyone has idea on it? or there are some existing
> implementation?
The semantics of tree concat vary, depending on what type of tree you
want to have. In the simplest case, it's unbalanced, so you can just do

concat :: Tree a -> Tree a -> Tree a
concat x y = Branch x y

if, on the other hand, you want to keep the tree balanced, or sorted,
or whatever, things get more involved.

(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

More information about the Beginners mailing list