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

2010-03-08 Thread Dan Weston
I think you want find :: Foldable t => (a -> Bool) -> t a -> Maybe a Jian Fan wrote: 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 root

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

2010-03-08 Thread MightyByte
I haven't tested it, but I think you're looking for something like this: searchTree2 :: (a -> Bool) -> TreeLoc a -> Maybe (TreeLoc a) searchTree2 pred rootLoc = if pred (getLabel rootLoc) then Just rootLoc else firstChild rootLoc >>= siblings where siblings loc = searchTree2 pred loc `

[Haskell-cafe] search Data.Tree.Zipper

2010-03-08 Thread Jian Fan
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 sear