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
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
Cai john writes: : | 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. I don't see how you could get that error from the code you posted, because the following errors turn up first: - Equations give different arities for "insert" - Constructor "Node" must have exactly 3 arguments in pattern If you fix those errors, *and* go on to define insertList along these lines insertList = something somethingElse *then* you do get a top-level overloading error, which you can remedy with either an explicit parameter insertList t = something somethingElse t or an explicit type signature insertList :: someType insertList = something somethingElse HTH.
participants (2)
-
Cai john -
Tom Pledger