@@ -229,6 +229,39 @@ delete l@(Loc r) =
229229 , parents: parents c
230230 }
231231
232+-- Searches
233+
234+-- | Search for the first occurence of the value `a` downwards and to the right.
235+findDown :: forall a. Eq a => a -> Loc a -> Maybe (Loc a)
236+findDown a l@(Loc r) =
237+ if a == (value l)
238+ then (Just l)
239+ else
240+ case next l of
241+ Just n -> findDown a n
242+ Nothing ->
243+ case down l of
244+ Just n' -> findDown a n'
245+ Nothing -> Nothing
246+
247+-- | Search for the first occurence of the value `a` upwards and to the left.
248+findUp :: forall a. Eq a => a -> Loc a -> Maybe (Loc a)
249+findUp a l@(Loc r) =
250+ if a == (value l)
251+ then (Just l)
252+ else
253+ case prev l of
254+ Just n -> findUp a n
255+ Nothing ->
256+ case up l of
257+ Just n' -> findUp a n'
258+ Nothing -> Nothing
259+
260+-- | Search for the first occurence of the value `a` starting from the root of
261+-- | the tree.
262+findFromRoot :: forall a. Eq a => a -> Loc a -> Maybe (Loc a)
263+findFromRoot a = (findDown a) <<< root
264+
232265-- Setters and Getters
233266node :: forall a. Loc a -> Tree a
234267node (Loc r) = r.node