Standard type for blit functions, and reusable code for validating blit arguments.
type ('src, 'dst) blit = src:'src -> src_pos:int -> dst:'dst -> dst_pos:int -> len:int -> unit
If blit : (src, dst) blit, then blit ~src ~src_pos ~len ~dst ~dst_pos blits len values from src starting at position src_pos to dst at position dst_pos. Furthermore, blit raises if src_pos, len, and dst_pos don't specify valid slices of src and dst.
type ('src, 'dst) blito = src:'src ->
?src_pos:int -> ?src_len:int -> dst:'dst -> ?dst_pos:int -> unit -> unit
type ('src, 'dst) sub = 'src -> pos:int -> len:int -> 'dst
If sub : (src, dst) sub, then sub ~src ~pos ~len returns a sequence of type dst containing len characters of src starting at pos.

subo is like sub, except pos and len are optional.

type ('src, 'dst) subo = ?pos:int -> ?len:int -> 'src -> 'dst
module type S = sig .. end
type t
val blit : (t, t) blit
val blito : (t, t) blito
val unsafe_blit : (t, t) blit
val sub : (t, t) sub
val subo : (t, t) subo
module type S1 = sig .. end
type 'a t
val blit : ('a t, 'a t) blit
val blito : ('a t, 'a t) blito
val unsafe_blit : ('a t, 'a t) blit
val sub : ('a t, 'a t) sub
val subo : ('a t, 'a t) subo
module type S_distinct = sig .. end
type src
type dst
val blit : (src, dst) blit
val blito : (src, dst) blito
val unsafe_blit : (src, dst) blit
val sub : (src, dst) sub
val subo : (src, dst) subo
Users of modules matching the blit signatures S, S1, and S1_distinct only need to understand the code above. The code below is only for those that need to implement modules that match those signatures.
module type Elt = sig .. end
type t
val equal : t -> t -> bool
of_bool is used to generate two distinct values of type t, used in unit tests. It is required that of_bool false <> of_bool true.
val of_bool : bool -> t
module type Sequence = sig .. end
type elt
type t
val create : len:int -> t
val length : t -> int
val get : t -> int -> elt
val set : t -> int -> elt -> unit
val sexp_of_t : t -> Sexplib.Sexp.t
module type Blit = sig .. end
include sig .. end with type __pa_nonrec_0 := ('a0, 'a1) blit
type ('a0, 'a1) __pa_nonrec_0 = ('a0, 'a1) blit
type ('src, 'dst) blit = ('src, 'dst) __pa_nonrec_0
include sig .. end with type __pa_nonrec_1 := ('a0, 'a1) blito
type ('a0, 'a1) __pa_nonrec_1 = ('a0, 'a1) blito
type ('src, 'dst) blito = ('src, 'dst) __pa_nonrec_1
include sig .. end with type __pa_nonrec_2 := ('a0, 'a1) sub
type ('a0, 'a1) __pa_nonrec_2 = ('a0, 'a1) sub
type ('src, 'dst) sub = ('src, 'dst) __pa_nonrec_2
include sig .. end with type __pa_nonrec_3 := ('a0, 'a1) subo
type ('a0, 'a1) __pa_nonrec_3 = ('a0, 'a1) subo
type ('src, 'dst) subo = ('src, 'dst) __pa_nonrec_3
module type S = S
module type S1 = S1
module type S_distinct = S_distinct
There are various Make* functors that turn an unsafe_blit function into a blit function. The functors differ in whether the sequence type is monomorphic or polymorphic, and whether the src and dst types are distinct or are the same.

The blit functions make sure the slices are valid and then call unsafe_blit. They guarantee at a call unsafe_blit ~src ~src_pos ~dst ~dst_pos ~len that:

        len > 0
        && src_pos >= 0
        && src_pos + len <= get_src_len src
        && dst_pos >= 0
        && dst_pos + len <= get_dst_len dst

The Make* functors also automatically create unit tests.

module Make : 
functor (Elt : Elt) ->
functor (Sequence : sig .. end) -> S with type t := Sequence.t
Make is for blitting between two values of the same monomorphic type.
module Make_distinct : 
functor (Elt : Elt) ->
functor (Src : Sequence with type elt := Elt.t) ->
functor (Dst : sig .. end) -> S_distinct with type src := Src.t with type dst := Dst.t
Make_distinct is for blitting between values of distinct monomorphic types.
module Make1 : 
functor (Sequence : sig .. end) -> S1 with type t := 'a Sequence.t
Make1 is for blitting between two values of the same polymorphic type.