[Haskell-cafe] Re: search Data.Tree.Zipper

Yitzchak Gale gale at sefer.org
Tue Mar 9 06:36:56 EST 2010

Jian Fan wrote:
> I somehow cannot figure this out. Tree is Foldable so I
> can use "find" on it. But how can I use find on TreeLoc?
> Am I missing something obvious?

But what exactly is a "TreeLoc"? Hoogle doesn't know about
it. If you created it yourself, you haven't showed us
how you defined it or what you are using it for.

In any case, below is one way to simplify the code you posted.
It is only a small simplification, but it is about the best I
can do without seeing the details of what you are trying to do.

Try posting this kind of question to the "haskell-beginners"
mailing list. There are people there who are much better at
answering this kind of question.

One thing that made it hard to follow your code was your
repeated use of "loc", one shadowing the other. Try to avoid

searchTree :: (a -> Bool) -> TreeLoc a -> Maybe (TreeLoc a)
searchTree pre rootLoc
 | pred (getLabel rootLoc) = Just rootLoc
 | otherwise               = do
     loc <- firstChild rootLoc
     searchTree pred loc `mplus` (right loc >>= searchTree pred)


More information about the Haskell-Cafe mailing list