TypeScript
HIR projection with file emission and end-to-end floors.
Part of the HIR lane. Every panel below is compiler output.
How to read it#
The largest expansion among the host languages, because Faber's typed numerics and tensors have no TypeScript counterpart and arrive as generated runtime scaffolding.
Measured support#
| Capable | Analyzable | Coverage |
|---|---|---|
| 573 | 573 | 100% |
From the target matrix: how many corpus exempla lower to this target. Coverage is not a quality score — an emitter can lower a term and still erase a distinction.
No measured gaps in the scored sections.
Typed tensors#
Builds two shaped matrices, multiplies them, and reduces the product to a scalar. Exercises shape-bearing types and a reduction.
Faber source
faber convert --to en — English reader surfacemain {
let list<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
let list<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
let tf32[2, 3] a ← flat_a ↦ tensor<f32, [2, 3]>
let tf32[3, 4] b ← flat_b ↦ tensor<f32, [3, 4]>
let tf32[2, 4] product ← a.matmul(b)
let f32 mean ← product.mean()
print mean
}faber convert --to la — canonical Faberincipit {
sit lista<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
sit lista<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
sit tf32[2, 3] a ← flat_a ↦ tensor<f32, [2, 3]>
sit tf32[3, 4] b ← flat_b ↦ tensor<f32, [3, 4]>
sit tf32[2, 4] product ← a.matmul(b)
sit f32 mean ← product.media()
nota mean
}faber convert --to th-TH — Thaiเริ่ม {
กำหนด รายการ<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
กำหนด รายการ<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
กำหนด tf32[2, 3] a ← flat_a ↦ เทนเซอร์<f32, [2, 3]>
กำหนด tf32[3, 4] b ← flat_b ↦ เทนเซอร์<f32, [3, 4]>
กำหนด tf32[2, 4] product ← a.คูณเมทริกซ์(b)
กำหนด f32 mean ← product.ค่าเฉลี่ย()
บันทึก mean
}faber convert --to zh-Hans — Simplified Chinese入口 {
设 列表<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
设 列表<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
设 tf32[2, 3] a ← flat_a ↦ 张量<f32, [2, 3]>
设 tf32[3, 4] b ← flat_b ↦ 张量<f32, [3, 4]>
设 tf32[2, 4] product ← a.矩阵乘法(b)
设 f32 mean ← product.均值()
显示 mean
}faber convert --to zh-Hant — Traditional Chinese入口 {
設為 列表<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
設為 列表<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
設為 tf32[2, 3] a ← flat_a ↦ 張量<f32, [2, 3]>
設為 tf32[3, 4] b ← flat_b ↦ 張量<f32, [3, 4]>
設為 tf32[2, 4] product ← a.矩陣乘法(b)
設為 f32 mean ← product.平均值()
註記 mean
}faber convert --to vi — Vietnamesebắt_đầu {
đặt danh_sách<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
đặt danh_sách<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
đặt tf32[2, 3] a ← flat_a ↦ ten_xo<f32, [2, 3]>
đặt tf32[3, 4] b ← flat_b ↦ ten_xo<f32, [3, 4]>
đặt tf32[2, 4] product ← a.nhân_ma_trận(b)
đặt f32 mean ← product.trung_bình()
ghi_chú mean
}faber convert --to ar — Arabicبداية {
ليكن قائمة<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
ليكن قائمة<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
ليكن tf32[2, 3] a ← flat_a ↦ موتر<f32, [2, 3]>
ليكن tf32[3, 4] b ← flat_b ↦ موتر<f32, [3, 4]>
ليكن tf32[2, 4] product ← a.ضرب_المصفوفات(b)
ليكن f32 mean ← product.المتوسط()
اعرض mean
}faber convert --to hi — Hindiआरंभ {
बैठा सूची<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
बैठा सूची<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
बैठा tf32[2, 3] a ← flat_a ↦ टेंसर<f32, [2, 3]>
बैठा tf32[3, 4] b ← flat_b ↦ टेंसर<f32, [3, 4]>
बैठा tf32[2, 4] product ← a.आव्यूह_गुणन(b)
बैठा f32 mean ← product.माध्य()
दिखाओ mean
}TypeScript — 9 lines in, 13 out (1.4×)
// Generated by radix - do not edit
import { display, tensor } from "@faber/runtime";
(() => { try { return (() => {
const l_flat_a: Array<number> = [1, 2, 3, 4, 5, 6];
const l_flat_b: Array<number> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const l_a: tensor.Tensor<number> = tensor.Tensor.fromArray<number>(l_flat_a, [2, 3], (value) => Number(value), undefined, (expected: number, actual: number) => `tensor conversion expected ${expected} elements, got ${actual}`);
const l_b: tensor.Tensor<number> = tensor.Tensor.fromArray<number>(l_flat_b, [3, 4], (value) => Number(value), undefined, (expected: number, actual: number) => `tensor conversion expected ${expected} elements, got ${actual}`);
const l_product: tensor.Tensor<number> = l_a.matmul(l_b, true);
const l_mean: number = l_product.media();
console.log(display.value(((x: number): string => { const v = Math.fround(x); if (!Number.isFinite(v)) { return display.value(v, "fractus"); } let e = v.toExponential(); for (let p = 0; p < 9; p++) { e = v.toExponential(p); if (Math.fround(Number(e)) === v) { break; } } const m = /^(-?)(\d)(?:\.(\d+))?e([+-]\d+)$/.exec(e) as RegExpExecArray; const sign = Object.is(v, -0) ? "-" : m[1]; const digits = m[2] + (m[3] ?? ""); const n = Number(m[4]); let body: string; if (n < 0) { body = "0." + "0".repeat(-n - 1) + digits; } else if (digits.length <= n + 1) { body = digits + "0".repeat(n + 1 - digits.length) + ".0"; } else { body = digits.slice(0, n + 1) + "." + digits.slice(n + 1); } return sign + body; })(l_mean), "textus"));
})(); } catch (__e: any) { const __m = __e instanceof Error ? (((__e as any).__faberAssertion === true || (__e as any).__faberAbort === true) ? "abort: " + __e.message : __e.message) : (__e !== null && typeof __e === "object" && (__e as any).__faberFail === true ? "abort: " + String((__e as any).error) : String(__e)); console.error((__e !== null && typeof __e === "object" && (__e as any).__faberTrap === true ? "error: " : (__e !== null && typeof __e === "object" && ((__e as any).__faberAssertion === true || (__e as any).__faberAbort === true || (__e as any).__faberFail === true) ? "" : "Error: ")) + __m); (globalThis as any).process.exitCode = 70; return 70; } })();The error channel#
A function that may fail, and a caller that catches. Shows how the ⇥ channel becomes each target's own error idiom.
Faber source
faber convert --to en — English reader surfacefn divide(int a, int b) → int ⇥ string {
if b ≡ 0 {
throw "division by zero"
}
return a / b
}
main {
do {
print divide(10, 2)
}
catch err {
warn err
}
}faber convert --to la — canonical Faberfunctio divide(numerus a, numerus b) → numerus ⇥ textus {
si b ≡ 0 {
iace "division by zero"
}
redde a / b
}
incipit {
fac {
nota divide(10, 2)
}
cape err {
mone err
}
}faber convert --to th-TH — Thaiฟังก์ชัน divide(จํานวน a, จํานวน b) → จํานวน ⇥ ข้อความ {
ถ้า b ≡ 0 {
โยน "division by zero"
}
คืน a / b
}
เริ่ม {
ทำ {
บันทึก divide(10, 2)
}
จับ err {
เตือน err
}
}faber convert --to zh-Hans — Simplified Chinese函数 divide(整数 a, 整数 b) → 整数 ⇥ 文本 {
如果 b ≡ 0 {
抛错 "division by zero"
}
返回 a / b
}
入口 {
执行 {
显示 divide(10, 2)
}
捕获 err {
警告 err
}
}faber convert --to zh-Hant — Traditional Chinese函式 divide(整數 a, 整數 b) → 整數 ⇥ 文字 {
若 b ≡ 0 {
拋出 "division by zero"
}
傳回 a / b
}
入口 {
執行 {
註記 divide(10, 2)
}
捕捉 err {
警告 err
}
}faber convert --to vi — Vietnamesehàm divide(số a, số b) → số ⇥ văn_bản {
nếu b ≡ 0 {
ném "division by zero"
}
trả a / b
}
bắt_đầu {
làm {
ghi_chú divide(10, 2)
}
bắt err {
cảnh_báo err
}
}faber convert --to ar — Arabicدالة divide(عدد a, عدد b) → عدد ⇥ نص {
إذا b ≡ 0 {
ارم "division by zero"
}
أعد a / b
}
بداية {
افعل {
اعرض divide(10, 2)
}
التقط err {
نبه err
}
}faber convert --to hi — Hindiफलन divide(संख्या a, संख्या b) → संख्या ⇥ पाठ {
यदि b ≡ 0 {
इधरफेंको "division by zero"
}
लौटाओ a / b
}
आरंभ {
करो {
दिखाओ divide(10, 2)
}
पकड़ो err {
चेताओ err
}
}TypeScript — 13 lines in, 21 out (1.6×)
// Generated by radix - do not edit
import { display, exact, result } from "@faber/runtime";
function divide(p_a: number, p_b: number): result.Result<number, string> {
if ((p_b as number) === 0) {
return { ok: false as const, error: "division by zero" };
}
return { ok: true as const, value: exact.store(exact.div(p_a, p_b), -9223372036854775808, 9223372036854775807, "i64", "return", "") };
}
(() => { try { return (() => {
const t0 = (() => { try { {
console.log(display.value((<T>(r: result.Result<T, any>): T => { if (!r.ok) { throw { __faberFail: true, error: r.error }; } return r.value; })(divide(10, 2)), "numerus"));
}return { ok: true as const, value: undefined }; } catch (__e: any) { if (__e !== null && typeof __e === "object" && __e.__faberFail === true) { return { ok: false as const, error: __e.error }; } throw __e; } })() as result.Result<any, string>;
if (!t0.ok) {
const l_err = (<T, E>(r: result.Result<T, E>): E => { if (!r.ok) { return r.error; } throw new Error("result error read on the success arm"); })(t0);
{
console.warn(l_err);
}}
})(); } catch (__e: any) { const __m = __e instanceof Error ? (((__e as any).__faberAssertion === true || (__e as any).__faberAbort === true) ? "abort: " + __e.message : __e.message) : (__e !== null && typeof __e === "object" && (__e as any).__faberFail === true ? "abort: " + String((__e as any).error) : String(__e)); console.error((__e !== null && typeof __e === "object" && (__e as any).__faberTrap === true ? "error: " : (__e !== null && typeof __e === "object" && ((__e as any).__faberAssertion === true || (__e as any).__faberAbort === true || (__e as any).__faberFail === true) ? "" : "Error: ")) + __m); (globalThis as any).process.exitCode = 70; return 70; } })();Collections and iteration#
A list folded to a total with for from. The plainest possible read on how loops lower.
Faber source
fn sum(list<int> numeri) → int {
mut int total ← 0
for from numeri let n {
total ← total + n
}
return total
}
main {
let list<int> valores ← [1, 2, 3, 4, 5]
print sum(valores)
}TypeScript — 12 lines in, 15 out (1.2×)
// Generated by radix - do not edit
import { display, exact } from "@faber/runtime";
function sum(p_numeri: Array<number>): number {
let l_total: number = 0;
for (const l_n of p_numeri) {
l_total = exact.store(exact.add(l_total, l_n), -9223372036854775808, 9223372036854775807, "i64", "assignment to `total`", "");
}
return l_total;
}
(() => { try { return (() => {
const l_valores: Array<number> = [1, 2, 3, 4, 5];
console.log(display.value(sum(l_valores), "numerus"));
})(); } catch (__e: any) { const __m = __e instanceof Error ? (((__e as any).__faberAssertion === true || (__e as any).__faberAbort === true) ? "abort: " + __e.message : __e.message) : (__e !== null && typeof __e === "object" && (__e as any).__faberFail === true ? "abort: " + String((__e as any).error) : String(__e)); console.error((__e !== null && typeof __e === "object" && (__e as any).__faberTrap === true ? "error: " : (__e !== null && typeof __e === "object" && ((__e as any).__faberAssertion === true || (__e as any).__faberAbort === true || (__e as any).__faberFail === true) ? "" : "Error: ")) + __m); (globalThis as any).process.exitCode = 70; return 70; } })();---