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.

∪

Declares a type alias.

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

Inline value unions and match on union variants.

Syntax: type <name> = <type> ∪ <type>

Category#

variant

Examples#

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

Inline value unions and match on union variants.

# =============================================================================
# ∪ — Inline value unions and match on union variants.
# =============================================================================
#
# What this teaches:
#   • Inline unions — `∪` creates ad-hoc union types without a full `union` declaration
#   • Tagged variants — `union` with `case` pattern matching for structured payloads
#
# Common mistakes:
#   • confusing unio (ad-hoc union type A ∪ B) with ∪ used as a set operator — unio is a type-level construct
#
# See also: type, match, union
# =============================================================================

# Inline value unions and match on union
#
# type Valor = int ∪ string models a non-nullable ad-hoc union.
# union + match handles tagged variants with payloads.
#
# GRAMMAR:
#   typeAlias :← 'type' ident '=' typeExpr ('∪' typeExpr)*
#   match  :← 'match' expr '{' 'case' variant pattern block ... '}'
#
# EXPECTED OUTPUT:
#   42, "salve", "n: 7", "t: faber"
#
# BACKEND: Inline-union `match` enum lowering gap on Rust (whitelist: unio/unio.fab).

type Valor = string ∪ int

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

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

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

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

    # --- Tagged union variants via variant ---

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

Expected output:

42
salve
n: 7
t: faber