การเรนเดอร์th-TH

ชนิดนามแฝง

Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH 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
}