let slice_exn ?(start=0) ?finish t =
let length_of_t = List.length t in
if start < 0 || (not (is_empty t) && start >= length_of_t) then
ksprintf failwith "slice_exn: invalid start %d" start
else
match finish with
| None -> sub_exn t ~index:start ~length:(length_of_t - start)
| Some f -> if f < 0 || f > length_of_t then
ksprintf failwith "slice_exn: invalid finish %d" f
else
sub_exn t ~index:start ~length:(f - start)