| Z -> Lazy.force (flatten tl)

- if n < 0 then invalid_arg "Cf_seq.limit: n < 0";

- | P (hd, tl) when n > 0 -> P (hd, limit (pred n) tl)

+ | P (hd, tl) when n > 0 -> P (hd, lazy (loop (pred n) tl))

+ if n < 0 then invalid_arg "Cf_seq.limit: n < 0";

let rec loop n = function

if n < 0 then invalid_arg "Cf_seq.shift: n < 0";

lazy (loop n (Lazy.force s))

+ match Lazy.force z with

+ | P (hd, tl) -> P (hd, sentinel x tl)

let rec loop stack = function

| P (hd, tl) -> loop (hd :: stack) (Lazy.force tl)

(** [limit n s] returns the sequence of all the elements in [s], up to [n]

elements in number and no more. Raises [Invalid_argument] if [n < 0].

+ If [?x] is provided, then the exception is raised if the sequence is

+ evaluated past the limit.

-val limit: int -> 'a t -> 'a t

+val limit: ?x:exn -> int -> 'a t -> 'a t

(** [shift n s] returns the sequence of all the elements in [s] after the first

[n] elements are discarded. Returns the empty sequence if [s] has fewer

val shift: int -> 'a t -> 'a t

+(** [sentinel x s] returns a sequence identical to [s] except that [x] is raised

+ by evaluating to the end. This is intended for use in incremental sequence

+val sentinel: exn -> 'a t -> 'a t

(** [reverse s] evaluates the entire sequence and composes a list of the

elements in reverse order. Tail recursive.