normalize length_fun thing_with_length i is just
i is negative, in which case it's
length_fun thing_with_length + i.
This is used by various python-style slice functions.
validate_pos_len_exn are intended to be used
by functions that take a sequence (array, string, bigstring, ...) and an optional
len specifying a subrange of the sequence. Such functions should call
get_pos_len with the length of the sequence and the optional
len, and it
will return the
len specifying the range, where the default
pos is zero
and the default
len is to go to the end of the sequence.
It should be the case that:
pos >= 0 && len >= 0 && pos + len <= length
Note that this allows
pos = length and
len = 0, i.e. an empty subrange
at the end of the sequence.
(pos', len') specifying a subrange where:
pos' = match pos with None -> 0 | Some i -> i len' = match len with None -> length - pos | Some i -> i