Im studying haskell at the university and Im stuck with a binaretree. There is something wrong with it but i cant find it :S
I need some help !!
data BinTree a = Empty | NodeBT a (BinTree a) (BinTree a) deriving Show
treeMember :: Ord a => a -> BinTree a -> Maybe a treeMember x Null = Nothing treeMember x ( NodeBT x’ left right ) | x == x’ = Just x’ | x < x’ = treeMember x left | x > x’ = treeMember x right
creatBinTree :: Ord a => BinTree a -> [a] -> BinTree a createBinTree [] = BinTree creatBinTree (x:xs) = createBinTree ( createBinTree x BinTree ) xs
inorder :: BinTree a -> [a] inorder Empty = [] inorder ( NodeBT x left right ) = inorder left ++ [x] ++ inorder right
tSort :: Ord a => [a] -> [a] tSort xx = inorder ( createBinTree Null xx)
tinsert :: Int ->
BinTree Int -> BinTree Int tinsert a Empty = (NodeBT a Empty Empty) tinsert a (NodeBT x lf rt) | a==x = NodeBT x lf rt | a<x = NodeBT x (tinsert a lf) rt | otherwise = NodeBT x lf (tinsert a rt)
I also have to figure out a simple code for counting the number of nodes and also treeMember to check if an element is in the tree.. im really confused
sandra_ba...@hotmail.com wrote: > Im studying haskell at the university and Im stuck with a binaretree. > There is something wrong with it but i cant find it :S
> I need some help !!
Homework? :-)
The usual question in this case is: What did you try, and where exactly are you stuck?
There are a few rather obvious little mistakes in the code. The usual way to fix them is to try to compile it, then move the cursor in the editor to the place where the compiler complains, and think hard about the compiler message and/or the type of the expression/pattern that is supposed to be at this place. And that's something you'll have to practice, so I'll only give you hints, not the solution.
You might also want to talk with some fellow students or your tutors about your code -- that feedback loop has less latency than a newsgroup :-)
Dirk Thierbach <dthierb...@usenet.arcornews.de> wrote: > You might also want to talk with some fellow students or your tutors > about your code
There's this legend of the MIT help desk requiring people to tell their problems to a teddy before asking humans. The same legend also claims that this practice reduced workload for the staff by magnitudes.
-- (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.
Achim Schneider <bars...@web.de> wrote: > Dirk Thierbach <dthierb...@usenet.arcornews.de> wrote: >> You might also want to talk with some fellow students or your tutors >> about your code > There's this legend of the MIT help desk requiring people to tell their > problems to a teddy before asking humans. The same legend also claims > that this practice reduced workload for the staff by magnitudes.
A friend of mine practiced her talks by giving them to a soccer ball. Word got round, and soon people starting saying "I have to go to talk to the soccer ball" when they meant "I've to think about that."
To get back to the original subject, that only works if you've already some idea of the whole topic, and just need to sort your thoughts out. If you have very little experience in programming, then talking to living people is a lot better :-)
>>> You might also want to talk with some fellow students or your tutors >>> about your code
>> There's this legend of the MIT help desk requiring people to tell their >> problems to a teddy before asking humans. The same legend also claims >> that this practice reduced workload for the staff by magnitudes.
Also known as rubber ducking. Discuss the problem with you rubber duck.
> A friend of mine practiced her talks by giving them to a soccer ball. > Word got round, and soon people starting saying "I have to go to > talk to the soccer ball" when they meant "I've to think about that."
> To get back to the original subject, that only works if you've already > some idea of the whole topic, and just need to sort your thoughts out. > If you have very little experience in programming, then talking to > living people is a lot better :-)