The new tree position annotation, and the corresponding command.

This commit is contained in:
aarne
2003-09-25 11:42:20 +00:00
parent 6e9258558a
commit 49f6288350
4 changed files with 23 additions and 2 deletions

View File

@@ -100,6 +100,16 @@ goLast :: Loc a -> Err (Loc a)
goLast = rep goAhead where
rep f s = err (const (return s)) (rep f) (f s)
goPosition :: [Int] -> Loc a -> Err (Loc a)
goPosition p = go p . goRoot where
go [] s = return s
go (p:ps) s = goDown s >>= apply p goRight >>= go ps
apply :: Monad m => Int -> (a -> m a) -> a -> m a
apply n f a = case n of
0 -> return a
_ -> f a >>= apply (n-1) f
-- added some utilities
traverseCollect :: Path a -> [a]