conversio-fallibilis
Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.
Three recovery postures for fallible 转换: inline ⊥ default, ⇥ propagation, and 执行/cape.
Syntax: <expression> ↦ <type> | 函数 … → T ⇥ E | 执行 { … } 捕获 err { … }
Category#
conversion
Related#
Examples#
radix/corpus/conversio/fallibilis.fab (canonical · conversio)#
Three recovery postures for fallible 转换: inline ⊥ default, ⇥ propagation, and 执行/cape.
# =============================================================================
# conversio-fallibilis — Three recovery postures for fallible 转换: inline ⊥ default, ⇥ propagation, and 执行/cape.
# =============================================================================
#
# What this teaches:
# • Recovery postures — three strategies for handling 变换 failure: inline `⊥` default, `⇥` propagation to callers, and `执行 { … } 捕获 err { … }` error absorption.
# • Type signatures — how `→ T ⇥ 文本` propagates 变换 error as a typed channel.
#
# Common mistakes:
# • Mixing propagation and inline recovery — bare `↦` without `⊥` inside a `→ T ⇥ 文本` function still propagates errors rather than handling them locally.
#
# See also: ↦, ⇥, ⊥, 执行, 捕获, 抛错
# =============================================================================
# 转换 fallibilis — inline ⊥ default, ⇥ propagation, and 执行/cape recovery
#
# Posture 1: `expr ↦ T ⊥ recovery` handles failure at the site.
# Posture 2: bare `↦` inside `→ T ⇥ 文本` propagates to callers.
# Posture 3: `执行 { … }` with `捕获 err { … }` absorbs propagated 转换 failure.
#
# BACKEND:
# Rust lowers all three postures (inline `⊥`, propagation, `执行`/`捕获`).
# Go/TS remain diagnostic-only until their failable stacks mature.
# Why: this function is itself the `⊥` default below, so it cannot default
# itself; epoch seconds 0 cannot fail to convert, so it needs no handler.
fn epochZero() → instant {
return 0 ↦ instant
}
fn parseInstans(value v) → instant ⇥ string {
return v ↦ instant
}
fn inlineRecovery(value v) → instant {
return v ↦ instant ⊥ epochZero()
}
fn tutum(value v) → instant {
do {
return parseInstans(v)
}
catch err {
warn err
return epochZero()
}
}
fn tutumDirect(value v) → instant {
do {
return v ↦ instant
}
catch err {
warn err
return epochZero()
}
}
main {
const value good ← "1979-05-27T07:32:00Z"
const value bad ← "not-a-datetime"
assert inlineRecovery(good) ≡ (good ↦ instant)
assert inlineRecovery(bad) ≡ epochZero()
assert tutum(good) ≡ (good ↦ instant)
assert tutum(bad) ≡ epochZero()
assert tutumDirect(good) ≡ (good ↦ instant)
assert tutumDirect(bad) ≡ epochZero()
print inlineRecovery(good), tutum(good), tutumDirect(good)
}