How to force recursion
Cai john
galaxy_xfi@yahoo.com
Mon, 9 Dec 2002 13:15:35 -0800 (PST)
I forgot to tell which kind Tree implementation I use:
so when I make a Tree I insert keys:
let a = mkTree
b = insert "tree"
c = insert "test"
d = insert "table"
in showTree -- show the contents of the tree
what I want to do is eliminate b,c & d into a
recursive function:
insertList tree [] = Empty
insertList tree (x:xs) = insertList(insert tree x)
but hugs is complaining about a top-level overloading
error.Any idea how to fix it, thanks.
--Tree
Tree a = Empty | Node a (Tree a ) (Tree a )
--here is the insert:
insert Empty key value = Node key Empty Empty
insert (Node a b left right) key | a == key =
Node a left right
| a < key =
Node a left (insert right key )
| otherwise =
Node a (insert left key) right
--- Cai john <galaxy_xfi@yahoo.com> wrote:
> How do I make this work:
>
> insertTree tree (x:xs) n = insertTree (insert tree a
> n) xs n
>
> insert -> common insertion into a tree which returns
> a
> tree
>
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up
> now.
> http://mailplus.yahoo.com
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com