Definition
A vector is a length-indexed list data type. Unlike ordinary lists, vectors carry their length as part of their type, enabling compile-time guarantees about size.
In Dependent Type Theory, vectors are typically defined as:
where is the element type and is the length. The type contains lists of exactly elements of type .
Construction
Vectors are typically constructed inductively:
- - The empty vector
- - Prepending an element increases the length by one
Examples
- - Vectors of exactly three natural numbers
- - The empty vector is unique
- Operations like are total because the type guarantees non-emptiness
Properties
- The length is statically known and checked by the type system
- Operations like indexing, head, and tail can be made total
- Vector concatenation has type:
- Vectors are an example of a Dependent Pair: represents lists with their length
Related Concepts
- Dependent Pair: Vectors with their length form a dependent pair
- Dependent Type Theory: The system enabling length-indexed types
- Type Constructor: Vector is a dependent type constructor