io7m
io7m-jtensors 7.0.0-beta0010
2.1
Vectors

- 2.1.1. Types
- 2.1.2. Access control
- 2.1.3. Storage
- 2.1.4. Phantom types

2.1.1
Types
1
The io7m-jtensors package provides vectors with single-precision (float) elements, double-precision (double) elements, integer (int), and long integer (long) elements. Each vector type is available in two, three, and four element versions. Each vector type is available in mutable or immutable versions. The package unambiguously identifies the vector types by using the following naming conventions for the types (given as a simple EBNF grammar), where prefix is a type-specific prefix:
2.1.1.1. Vector type naming

    prefix       = ...
    mutability   = "M" | "I" ;
    size         = "2" | "3" | "4" ;
    element_type = "I" | "L" | "F" | "D" ;
    type         = prefix , mutability , size , element_type ;

2.1.2
Access control
1
If a function only needs to read from a value of a vector type, then it would be desirable to be able to statically enforce this fact. Therefore, the package provides a set of Readable interfaces that all vector types implement. By writing a function that takes a value of a type implementing a Readable interface, the programmer is implicitly stating that this function does not modify the vector.
2.1.2.1. Available vector Readable types

- VectorReadable2IType
- VectorReadable2FType
- VectorReadable2DType
- VectorReadable2LType
- VectorReadable3IType
- VectorReadable3FType
- VectorReadable3DType
- VectorReadable3LType
- VectorReadable4IType
- VectorReadable4FType
- VectorReadable4DType
- VectorReadable4LType

2
Conversely, if a function writes to the elements of a vector without ever reading from it, it again would be desirable to statically enforce this fact. The package provides Writable interfaces that all mutable vector types implement:
2.1.2.2. Available vector Writable types

- VectorWritable2IType
- VectorWritable2FType
- VectorWritable2DType
- VectorWritable2LType
- VectorWritable3IType
- VectorWritable3FType
- VectorWritable3DType
- VectorWritable3LType
- VectorWritable4IType
- VectorWritable4FType
- VectorWritable4DType
- VectorWritable4LType

3
Finally, a combination of the above interfaces is provided that essentially abstracts over mutable vector types. This allows the programmer to write code against pure interfaces without referring to a specific type, and to freely substitute alternative implementations at any time.
2.1.2.3. Available vector interface types

- Vector2IType
- Vector2FType
- Vector2DType
- Vector2LType
- Vector3IType
- Vector3FType
- Vector3DType
- Vector3LType
- Vector4IType
- Vector4FType
- Vector4DType
- Vector4LType

2.1.3
Storage
1
As with all matrix types, all vector types have associated Context types that allow for all methods to execute without allocating any memory. See the linked section for details.
2.1.4
Phantom types
1
The io7m-jtensors package also provides copies of the existing vector types indexed by a phantom type parameter in order to allow the programmer to make semantically distinct values type-incompatible [1].
2
The parameterized vector types and interfaces are provided in the com.io7m.jtensors.parameterized package.

[1]
See http://io7m.com/documents/tt1-pt/.