渲染zh-Hant

型別

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant 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
}