Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

type

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Declares a type alias.

Aliases: type

Syntax: type <name> = <type>

Category#

type

Examples#

radix/corpus/reference/keyword/typus/typus.fab (canonical · keyword)#

Declares a type alias.

# =============================================================================
# type — Declares a type alias.
# =============================================================================
#
# What this teaches:
#   • Type aliases — `type` for creating shorthand names for complex types
#   • Generic aliases — aliases can wrap generic types like `list<T>` and `map<K,V>`
#
# Common mistakes:
#   • confusing type (type alias) with class (nominal type) — type creates a transparent alias, not a new type
#
# See also: class, interface, object, ∪
# =============================================================================

# Type aliases
#
# type Nomen = Typus
#
# GRAMMAR:
#   typeAliasDecl :← 'type' ident '=' typeExpr
#
# EXPECTED OUTPUT:
#   42, "Marcus", true, ["Gaius", "Lucius", "Titus"], [100, 95, 87]

# --- Primitive type aliases ---

type Signum = int

type Cognomen = string

type Viget = bool

# --- Generic type aliases ---

type Nomina = list<string>

type Puncta = list<int>

type Index = map<string, int>

# Nullable type alias (canonical T ∪ none form)
type NomenOptivum = string ∪ none

main {
    # Using primitive aliases
    let Signum signum ← 42
    let Cognomen cognomen ← "Marcus"
    let Viget viget ← true
    print signum
    print cognomen
    print viget

    # Using generic aliases
    let Nomina sodales ← ["Gaius", "Lucius", "Titus"]
    print sodales
    let Puncta puncta ← [100, 95, 87]
    print puncta
}

Expected output:

42
Marcus
true
["Gaius", "Lucius", "Titus"]
[100, 95, 87]

radix/corpus/reference/reject/typus/alias-cycle-reject.fab (supporting · reject)#

A type alias cycle is a check error.

# =============================================================================
# type — A type alias cycle is a check error
# =============================================================================
# Each alias names another alias, and the pair never reaches a concrete type.
# An alias is transparent, so `A` must equal `B` must equal `A`: no type exists
# to give the binding. Break the cycle by making one member name a real type.

type A = B
type B = A

main {
    let A a ← 1
    print a
}

Expected: compilation rejects this example.