I want to create a tree structure in haskell so that later I can do a depth first search on it to find something.
Here is an example I have thought of to try and understand the concept -
data Tree a = Nil | Node a (Tree a) (Tree a) deriving (Show) createTree :: ([String],Int) -> Tree ([String],Int) createTree (,0) = Nil createTree ([x],n) = Node x (createTree removeOne ([x],n)) (createTree removeOne ([x],n)) removeOne :: ([String],Int) -> ([String],Int) removeOne (,0) = (,0) removeOne (x:xs, n)= (xs, n-1)
does this make sense? Can I do this? Have a stopping condition when the node should not be made and meanwhile keep making nodes?
At the moment I am getting an error:
ERROR "C:\Documents and Settings\Parul Sharma\Desktop\t.hs":7 - Type error in application
*** Expression : createTree removeOne ([x],n)
*** Term : createTree
*** Type : ([String],Int) -> Tree ([String],Int)
*** Does not match : a -> b -> c
How can I resolve this? Or am I going about constructing a tree and its branches incorrectly?