Abstract

Types representing slices of arrays.

This module defines various module types and modules for working with slices of arrays at different levels of granularity. None of the functionality here is particularly advanced or difficult to implement, but it is useful as a common interface for other containers.

Synopsis

module type slice = {
type slice 'a
val mk 'a: (i: i64) -> (n: i64) -> slice a
val unmk 'a: slice a -> (i64, i64)
val get [n] 'a: slice a -> [n]a -> ?[k].[k]a
}
module slice: slice
module mk_slice_key: (E: key with ctx = ()) -> key with ctx = []E.key with key = slice.slice E.key

Description

module type slice

An array slice represents a contiguous interval of some array. Essentially, a slice is an offset and a length. The slice does not contain a reference to the array in question. This is mostly useful for working with arrays of slices, as this would otherwise lead to irregular arrays-of-arrays.

type slice 'a

An array slice. The a parameter is merely a phantom type.

val mk 'a: (i: i64) -> (n: i64) -> slice a

Construct an array slice from an offset and a length.

val unmk 'a: slice a -> (i64, i64)

Deconstruct array slice into offset and length. The following property holds:

unmk (mk i n) == (i,n)
val get [n] 'a: slice a -> [n]a -> ?[k].[k]a

Retrieve the elements corresponding to some slice of an array. This may fail if the slide is out-of-bounds.

module slice
module mk_slice_key

Create a key for slices of some specific element type. The element type must also be provided with a key module for which the context is unit.