
8 Mar
2010
8 Mar
'10
1:11 p.m.
Hi, There doesn't seem to be a function to search the tree so I come up with following function: searchTree :: (a -> Bool) -> TreeLoc a -> Maybe (TreeLoc a) searchTree pred rootLoc = if pred (getLabel rootLoc) then Just rootLoc else case firstChild rootLoc of Just loc -> case searchTree pred loc of Just loc -> Just loc Nothing -> case right loc of Just rLoc -> searchTree pred rLoc Nothing -> Nothing Nothing -> Nothing Which feels quite ugly. Any suggestions? Thanks. Jian