Skip to content

Introduce numeric vectors as a first-class value type #684

Description

@Seddryck

Summary

Introduce a first-class numeric Vector value type with constructor syntax V(...).

A vector is a fixed-size positional value whose components are numeric. It is distinct from a tuple, which may contain heterogeneous values, but it shares the tuple's positional/structural behavior.

Syntax

V(1, 2, 3)
V(0.5, -2, 10)

Vector construction requires numeric components.

V(1, "foo", 3)

is invalid because vectors are numeric.

Relationship with tuples

Vectors should conceptually inherit the tuple structural contract: every function that applies to tuples and remains semantically valid for vectors must also accept vectors.

For example, tuple operations such as:

V(10, 20, 30) | arity
V(10, 20, 30) | pick(2, 0)
V(10, 20) | extend(V(30, 40))

must be available for vectors without duplicating their implementations merely because the runtime value kind differs.

However, a vector remains a distinct language/runtime type:

T(1, 2, 3)
V(1, 2, 3)

must not become interchangeable solely because both happen to contain numeric values.

Tuple-compatible operations that construct a positional result preserve Vector when the input is a Vector, the operation is defined for vectors, and every resulting component is numeric. If such an operation would introduce any nonnumeric component, it returns #null; it does not throw and does not implicitly demote the value to Tuple. A tuple is never promoted merely because all of its elements are numeric. Conversion from vector to tuple must be explicit. This preservation and rejection policy must be encoded centrally rather than independently in each function.

Vector-specific operations

The new type enables vector operations such as:

  • dot(vector)
  • magnitude
  • normalize
  • distance(vector)
  • scale(factor)

These operations should accept Vector, not generic arrays or tuples.

Spread / construction

Vector construction should follow the same positional construction principles as tuples where appropriate. If tuple spread is supported, equivalent vector spread should be considered when the spread value is itself a vector, while preserving the numeric-only invariant.

Type model

Conceptually:

Tuple
  fixed-size positional structure
  heterogeneous values allowed

Vector
  fixed-size positional structure
  numeric values only
  inherits tuple-compatible structural operations
  adds vector-specific numeric operations

This does not require CLR inheritance specifically; the implementation may use a shared positional abstraction or type hierarchy. The language-level behavior is the requirement.

Acceptance criteria

  • Add Vector as a first-class Expressif value type.
  • Add V(...) construction syntax.
  • All vector components must be numeric.
  • Empty-vector behavior is explicitly defined.
  • V(...) remains distinguishable from T(...) at runtime/type-binding level.
  • Tuple functions whose contracts apply to positional values are available for vectors.
  • Shared tuple/vector behavior is implemented through a common abstraction rather than duplicated function sets.
  • Vector-specific function binding can require Vector input.
  • Parser, binder, runtime value model, type metadata, documentation, and conformance tests cover vectors.
  • Tests cover valid vectors, invalid non-numeric components, tuple-vs-vector distinction, and inherited tuple-function behavior.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions