ratio
Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.
Labeled ad-hoc record type: construction, .name access, objectPattern, and holes.
Aliases: record
Syntax: record<label: type, …> { label = value }
Category#
type
Related#
Examples#
radix/corpus/ratio/ratio.fab (canonical · keyword)#
Labeled ad-hoc record type: construction, .name access, objectPattern, and holes.
# =============================================================================
# ratio — Labeled ad-hoc aggregate (promoted Type::Record).
# =============================================================================
#
# What this teaches:
# • labeled type args: record<g: f32, w: int>
# • construction: record<g: f32, w: int> { g = 1.0, w = 2 }
# (both spellings construct: en `record` and canonical `ratio`; the
# constructor head canonicalizes to `ratio` at parse — unit 047eef65)
# • .name access: point.g (labels only — no bracket form)
# • objectPattern destructuring: const {g, w} ← point
# • partial + rest: const {loss, rest leftover} ← metrics
# • element holes: record<g: _> solved from the construction witness
# • binary cup element: record<g: string ∪ null>
#
# Reject teaching rows (comments only; these must not become stage-3 inputs):
# • positional access attempt: point[0] / point.0
# • missing label: record<f32>
# • ∪ slot: record<g: ∪>
# • record ↦ class fence: r ↦ P (use reconstruction P { g = r.g })
#
# See also: genus, ceteri, iuncta
# =============================================================================
main {
# Construction and .name access.
# Same-locale surface: the en type-head `record` claims the constructor
# slot too (map-in-both, unit 047eef65); the canonical `ratio` spelling
# still constructs (hole site below).
const record<g: f32, w: int> point ← record<g: f32, w: int> { g = 1.0, w = 2 }
print point.g
print point.w
# Element hole solved from the construction witness.
const record<g: _, w: int> hole ← ratio<g: f32, w: int> { g = 1.0, w = 2 }
print hole.g + 0.0
print hole.w
# A wanted union element is a binary cup, not ∪ in the slot.
const record<g: string ∪ null> cup ← ratio<g: string ∪ null> { g = "x" }
print cup.g
# objectPattern binds by label.
const {g, w} ← point
print g
print w
# Partial by-label binding; rest is the unbound sub-record.
const record<loss: f32, steps: int> metrics ← ratio<loss: f32, steps: int> { loss = 3.0, steps = 4 }
const {loss, rest leftover} ← metrics
print loss
print leftover.steps
}Expected output:
1.0
2
1.0
2
x
1.0
2
3.0
4