T Programming Language - type-system

Type System

T currently has an alpha-stage, mode-aware type system. The implementation focuses on typed lambda signatures and strict validation for top-level functions, with broader static typing features planned for later phases.

Why this exists

The typing design in spec_files/typing_system.md sets a dual goal:

PRs #83 and #84 introduced the first concrete implementation of that plan: typed lambda syntax, generic parameter declarations, and strict-mode validation behavior.

Execution modes

Two checker modes are available:

Current behavior

In strict mode, only top-level lambda assignments are validated today.

Lambda syntax

T supports both untyped and typed lambda forms.

Untyped lambda

Body is any expression.

add = \(x, y) x + y

Typed lambda

Return type annotation is included inside the parameter parentheses.

add_int = \(x: Int, y: Int -> Int) (x + y)

Generic typed lambda

Generic type variables must be declared explicitly with <...>.

id = \<T>(x: T -> T) x
pair = \<A, B>(x: A, y: B -> Tuple[A, B]) [x, y]

Type annotation forms currently parsed

Base types

Composite forms

Generic variables

Single uppercase identifiers are interpreted as type variables (for example T, A, B).

What strict mode validates today

In strict mode, for top-level lambdas assigned with name = \(...) ..., T validates:

  1. all parameters have type annotations,
  2. return type is annotated,
  3. if type variables are used, generic parameters are declared,
  4. all used type variables are declared.

If any rule fails, evaluation is blocked with a type error.

What is not implemented yet

The current implementation is intentionally narrow. The following items from the spec are still future work:

In other words, this is a signature validation layer, not yet a full static typechecker.

Practical guidance

References