Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun focus (x :: xs, ys) = SOME (x, xs, ys)
- | focus _ = NONE
- fun first xs = focus (xs, nil)
- fun next (x, xs, ys) = focus (xs, x :: ys)
- fun focused (x, _, _) = x
- fun restore (x, xs, ys) = (rev ys, x :: xs)
- fun loop (_, NONE) = NONE
- | loop (x, SOME xs) =
- if x = focused xs then
- SOME xs
- else
- loop (x, next xs)
- fun splitAtFirst (x, xs) =
- case loop (x, first xs) of
- NONE => (xs, nil)
- | SOME xs => restore xs
- fun loop (_, xs, NONE) = xs
- | loop (x, xs, SOME ys) =
- if x = focused ys then
- loop (x, SOME ys, next ys)
- else
- loop (x, xs, next ys)
- fun splitAtLast (x, xs) =
- case loop (x, NONE, first xs) of
- NONE => (xs, nil)
- | SOME xs => restore xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement