Kết xuấtvi

∪

Declares a type alias.

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Inline value unions and phân_tích on hợp_nhất variants.

Syntax: kiểu_tên <name> = <type> ∪ <type>

Category#

type

Examples#

radix/corpus/unio/unio.fab (canonical · operator-group)#

Inline value unions and phân_tích on hợp_nhất variants.

# =============================================================================
# ∪ — Inline value unions and phân_tích on hợp_nhất variants.
# =============================================================================
#
# What this teaches:
#   • Inline unions — `∪` creates ad-hoc union types without a full `hợp_nhất` declaration
#   • Tagged variants — `hợp_nhất` with `trường_hợp` pattern matching for structured payloads
#
# Common mistakes:
#   • confusing unio (ad-hoc union kiểu_tên A ∪ B) with ∪ used as a set operator — unio is a type-level construct
#
# See also: kiểu_tên, phân_tích, hợp_nhất
# =============================================================================




# Inline value unions and phân_tích on hợp_nhất
#
# kiểu_tên Valor = số ∪ văn_bản models a non-nullable ad-hoc union.
# hợp_nhất + phân_tích handles tagged variants with payloads.
#
# GRAMMAR:
#   typeAlias :← 'kiểu_tên' ident '=' typeExpr ('∪' typeExpr)*
#   phân_tích  :← 'phân_tích' expr '{' 'trường_hợp' variant pattern block ... '}'
#
# EXPECTED OUTPUT:
#   42, "salve", "n: 7", "t: faber"
#
# BACKEND: Inline-union `phân_tích` enum lowering gap on Rust (whitelist: unio/unio.fab).

type Valor = int ∪ string

union Forma {
    Numerus { int v },
    Textus { string v }
}

fn describe(Forma f) → string {
    match f {
        case Numerus const v { return "n: §"(v) }
        case Textus const v { return "t: §"(v) }
    }
}

main {
    # --- Ad-hoc inline union values ---

    const Valor a ← 42
    const Valor b ← "salve"
    print a
    print b

    # --- Tagged hợp_nhất variants via tạo ---

    print describe(variant Numerus { v = 7 } ∷ Forma)
    print describe(variant Textus { v = "faber" } ∷ Forma)
}

Expected output:

42
salve
n: 7
t: faber