Skip to content

Tagged union

Represent a value as exactly one member of a fixed family of payload alternatives together with a discriminator that records the active alternative and governs safe elimination or pattern matching.

Version
v1 · 2026-08-30 · History
Domain-specific #
2929
Origin domain
computer science
Subdomain
programming languages and data representation

Core Idea

A tagged union, also called a discriminated union or variant, is a sum-like data representation whose value contains one alternative payload and a tag identifying which alternative is active. Construction couples a label with a payload of the label's declared type; elimination inspects the label and exposes the correspondingly typed payload, while exhaustive case analysis accounts for the closed alternative family The abstraction is therefore identified by a declared carrier, a transformation or constraint over that carrier, and an invariant that tells an analyst whether the named structure is genuinely present.

Scope of Application

Tagged union belongs to computer science and is useful where the analyst can specify a finite family of alternative payload types or record shapes and a value inhabiting exactly one labeled alternative, then evaluate the discriminator and payload remain consistent so that the active case can be recovered without guessing from overlapping representation. The scope is broad within that domain but bounded by the need for the discriminator and payload remain consistent so that the active case can be recovered without guessing from overlapping representation. The reference identity is semantic rather than one memory layout; representation optimizations qualify only when they preserve the active-case and typed-elimination contract.

Clarity

The abstraction clarifies a crowded vocabulary by making the discriminator and payload remain consistent so that the active case can be recovered without guessing from overlapping representation the center of the account. A claim should name the carrier, the governing operation or relation, the applicable assumptions, and the recognition test. A bare label is insufficient because tagged union, discriminated union, variant, sum type, and enum overlap differently across languages, while union type can also denote an untagged or structural type operation.

Manages Complexity

Without the abstraction, an analyst must reason directly over many local details: the carrier roles, admissibility assumptions, competing conventions, derived invariants, boundary cases, and proof or validation obligations specific to Tagged union. Tagged union compresses them into the roles in the structural signature. That compression permits comparison across instances without erasing the variables that determine validity. It also exposes which details may be varied safely and which are constitutive.

Abstract Reasoning

  1. Identify the carrier. State what the elements, states, objects, or observations are: a finite family of alternative payload types or record shapes and a value inhabiting exactly one labeled alternative. Reject examples whose alleged carrier belongs to a different problem. 2. Lock the constitutive rule. Express the discriminator and payload remain consistent so that the active case can be recovered without guessing from overlapping representation independently of one notation or implementation.

Knowledge Transfer

Knowledge transfers strongly among subfields of computer science because they reuse a finite family of alternative payload types or record shapes and a value inhabiting exactly one labeled alternative, Construction couples a label with a payload of the label's declared type; elimination inspects the label and exposes the correspondingly typed payload, while exhaustive case analysis accounts for the closed alternative family, and list the alternatives, type each payload, identify how the active case is encoded, verify construction preserves tag-payload agreement, and check that elimination dispatches only to the matching payload interpretation.

Relationships to Other Abstractions

Local relationship map for Tagged unionParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Tagged unionDOMAINPrime abstraction: Data Structure — is a kind ofData StructurePRIME

Current abstraction Tagged union Domain-specific

Parents (1) — more general patterns this builds on

  • Tagged union is a kind of Data Structure Prime

    The proposed strict upward parent is prime:data_structure.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Tagged union sits in a sparse region of the domain-specific corpus (64th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Syntax, Rewriting & Declarative Form (41 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-09-08