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