渲染zh-Hans

类型

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.

Declares a type alias.

Aliases: type

Syntax: 类型 <name> = <type>

Category#

type

Examples#

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

Declares a type alias.

# =============================================================================
# 类型 — Declares a type alias.
# =============================================================================
#
# What this teaches:
#   • Type aliases — `类型` for creating shorthand names for complex types
#   • Generic aliases — aliases can wrap generic types like `列表<T>` and `映射<K,V>`
#
# Common mistakes:
#   • confusing 类型 (type alias) with 类 (nominal type) — 类型 creates a transparent alias, not a new type
#
# See also: 类, 契约, 对象, ∪
# =============================================================================




# Type aliases
#
# 类型 Nomen = Typus
#
# GRAMMAR:
#   typeAliasDecl :← '类型' ident '=' typeExpr
#
# EXPECTED OUTPUT:
#   42, "Marcus", 真, ["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 ∪ 空类型 form)
type NomenOptivum = string ∪ none

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

    print signum
    print cognomen
    print viget

    # Using generic aliases
    const Nomina sodales ← ["Gaius", "Lucius", "Titus"]
    print sodales

    const Puncta puncta ← [100, 95, 87]
    print puncta
}