↦
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.
Converts a value with explicit runtime parsing or coercion semantics.
Aliases: convert, conversio
Syntax: <expression> ↦ <type> [⊥ <recovery>]
Category#
conversion
Related#
- ∷
- ⊥
Examples#
radix/corpus/conversio/conversio.fab (canonical · operator-group)#
Converts a value with explicit runtime parsing or coercion semantics.
# =============================================================================
# ↦ — Converts a value with explicit runtime parsing or coercion semantics.
# =============================================================================
#
# What this teaches:
# • Core แปลง — the `↦` operator converts between types with explicit parsing (ข้อความ→จํานวน) and coercion (จํานวน→ข้อความ).
# • Default with `⊥` — the `⊥` operator supplies a default value when แปลง fails at runtime (`⇥` only names error types).
# • Chaining — `↦` composes left-to-right for roundtrip conversions.
#
# Common mistakes:
# • Confusing `∷` (compile-time type ascription) with `↦` (runtime แปลง) and using `vel` instead of `⊥` for การแปลง recovery.
#
# See also: ∷, ⊥
# =============================================================================
# การแปลง — type แปลง operator (↦)
#
# <expr> ↦ <ชนิดนามแฝง>
# <expr> ↦ <ชนิดนามแฝง><params>
#
# GRAMMAR:
# convertExpr :← expr '↦' type
#
# EXPECTED OUTPUT:
# conversio.expected
#
# BACKEND:
# Siblings radix.fab and bivalens.fab compile-only until Go semantics align.
main {
# ↦ converts ข้อความ → จํานวน
let n1 ← "42" ↦ int
# ⊥ supplies a default on failure
let n2 ← "invalid" ↦ int ⊥ 0
let n3 ← "255" ↦ i32
let f1 ← "3.14159" ↦ float
let f2 ← "invalid" ↦ float ⊥ 0.0
let s1 ← 42 ↦ string
let s2 ← 3.14 ↦ string
let s3 ← true ↦ string
# chained ↦ left-to-right
let roundtrip ← ("42" ↦ int) ↦ string
print n1
print n2
print n3
print f1
print f2
print s1
print s2
print s3
print roundtrip
}Expected output:
42
0
255
3.14159
0.0
42
3.14
true
42