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

Jian Fan abemud at gmail.com
Mon Mar 8 15:06:48 EST 2010


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?

Dan Weston <westondan at imageworks.com> wrote:
> 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 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
>> 
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>> 
>> 



More information about the Haskell-Cafe mailing list