= Solution
With nonpositive counts treated as in the standard <list> operations:
``
takeSeq :: Integer -> Seq a -> Seq a
takeSeq n s
| n <= 0 = const []
| otherwise = \v -> takeWhile (< n) (s v)
dropSeq :: Integer -> Seq a -> Seq a
dropSeq n s
| n <= 0 = s
| otherwise = \v -> map (subtract n) (dropWhile (< n) (s v))
``
An occurrence survives `takeSeq n` exactly when its original index is less than $n$, and its index stays unchanged. It survives `dropSeq n` exactly when its original index is at least $n$, and its new index is the original one minus $n$. Sorted occurrence lists justify `takeWhile` and `dropWhile`. No equality constraint on the element type is needed because the operations only transform positions. The first guard also lets `takeSeq 0 s v` return `[]` without inspecting `s v`.
Back to article page