generic-defaults
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Generic parameter defaults declared with = ; explicit arguments and inference beat the default.
Syntax: fn f<T = string, size D = 64>(...) — binding order: explicit, then inference, then the declared default
Category#
type
Related#
Examples#
radix/corpus/generic/generic-defaults.fab (canonical · concept)#
Generic parameter defaults declared with = ; explicit arguments and inference beat the default.
# =============================================================================
# generic-defaults — Generic parameter defaults with the = spelling
# =============================================================================
#
# What this teaches:
# • Generic parameters may declare compile-time defaults: T = string and size D = 64.
# • Binding order at each call: explicit arguments, then inference, then the declared default.
# • Related keywords: fn, size
#
# Common mistakes:
# • Defaults must trail — a parameter without a default may not follow one — and `=` here is a compile-time fact, not the removed vel/coalesce runtime fallback.
#
# See also: generic, generic-call-type-args, fn
# =============================================================================
# generic-defaults — declared = defaults on generic parameters
#
# GRAMMAR:
# genericParam :← ident genericTypeDefault? | 'size' ident genericSizeDefault?
# genericTypeDefault :← '=' typeAnnotation
# genericSizeDefault :← '=' NATURAL
#
# EXPECTED OUTPUT:
# 42
# media
#
# Explicit and inferred witnesses beat the declared default: pick<int>(42)
# binds T explicitly; pick("media") infers T from the argument. Neither
# call consults `T = string`.
#
# BACKEND: A call whose default actually fires has no call-site MIR
# evidence until specialization consumes the resolved binding vector.
# Defaulted call sites (fallback(), and bounded(1) relying on
# `size D = 64` with D absent from the shapes) are declared here and
# proven by `faber check` and the semantic binder; their execution is
# deferred (whitelist: generic/generic-defaults.fab).
fn pick<T = string>(T x) → T {
return x
}
fn fallback<T = string>() → string {
return "salve"
}
fn bounded<size D = 64>(int x) → int {
return x
}
main {
print pick<int>(42)
print pick("media")
}Expected output:
42
media