Kết xuấtvi

conversio-fallibilis

Translation status: Tiếng Việt reader-locale proof. Code fences render through the vi pipeline; prose is canonical Latin.

Three recovery postures for fallible conversio: inline ⇥, ⇥ propagation, and fac/cape.

Syntax: <expression> ↦ <type> | functio … → T ⇥ E | fac { … } cape err { … }

Category#

conversion

Examples#

radix/corpus/conversio/fallibilis.fab (canonical · conversio)#

Three recovery postures for fallible conversio: inline ⇥, ⇥ propagation, and fac/cape.

# =============================================================================
# conversio-fallibilis — Three recovery postures for fallible conversio: inline ⇥, ⇥ propagation, and fac/cape.
# =============================================================================
#
# What this teaches:
#   • Recovery postures — three strategies for handling conversion failure: inline `⇥` fallback, `⇥` propagation to callers, and `fac { … } cape err { … }` error absorption.
#   • Type signatures — how `→ T ⇥ textus` propagates conversion error as a typed channel.
#
# Common mistakes:
#   • Mixing propagation and inline recovery — bare `↦` without `⇥` inside a `→ T ⇥ textus` function still propagates errors rather than handling them locally.
#
# See also: ↦, ⇥, fac, cape, iace
# =============================================================================

# conversio fallibilis — inline ⇥, propagation, and fac/cape recovery
#
# Posture 1: `expr ↦ T ⇥ recovery` handles failure at the site.
# Posture 2: bare `↦` inside `→ T ⇥ textus` propagates to callers.
# Posture 3: `fac { … }` with `cape err { … }` absorbs propagated conversio failure.
#
# BACKEND:
#   Rust lowers all three postures (inline `⇥`, propagation, `fac`/`cape`).
#   Go/TS remain diagnostic-only until their failable stacks mature.

fn epochZero()  instant {
    return "1970-01-01T00:00:00Z" ↦ 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)
}