Faber
Canonical re-emission — the compiler printing the program back.
Part of the HIR lane. Every panel below is compiler output.
How to read it#
The round trip. Reader-locale spellings and formatting normalise to the canonical surface, which is how a program written in one locale can be reviewed in another.
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 format --locale en — English reader surfacemain {
const list<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
const 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]
const tensor<f32, []> seed ← vacua
const tensor<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
const tensor<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
const tensor<f32, [2, 4]> product ← a.matmul(b)
const f32 mean ← product.media()
print mean
}faber format --locale la — canonical Faberincipit {
fixum lista<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
fixum 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]
fixum tensor<f32, []> seed ← vacua
fixum tensor<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
fixum tensor<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
fixum tensor<f32, [2, 4]> product ← a.matmul(b)
fixum f32 mean ← product.media()
nota mean
}faber format --locale 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]
คงที่ เทนเซอร์<f32, []> seed ← เซตว่าง
คงที่ เทนเซอร์<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
คงที่ เทนเซอร์<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
คงที่ เทนเซอร์<f32, [2, 4]> product ← a.matmul(b)
คงที่ f32 mean ← product.media()
บันทึก mean
}faber format --locale 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]
常量 张量<f32, []> seed ← 空集
常量 张量<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
常量 张量<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
常量 张量<f32, [2, 4]> product ← a.matmul(b)
常量 f32 mean ← product.media()
显示 mean
}faber format --locale 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]
定值 張量<f32, []> seed ← 空集
定值 張量<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
定值 張量<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
定值 張量<f32, [2, 4]> product ← a.matmul(b)
定值 f32 mean ← product.media()
註記 mean
}faber format --locale vi — Vietnamesebắt_đầu {
hằng danh_sách<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
hằng 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]
hằng ten_xo<f32, []> seed ← tập_rỗng
hằng ten_xo<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
hằng ten_xo<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
hằng ten_xo<f32, [2, 4]> product ← a.matmul(b)
hằng f32 mean ← product.media()
ghi_chú mean
}faber format --locale 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]
ثابت موتر<f32, []> seed ← فارغ
ثابت موتر<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
ثابت موتر<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
ثابت موتر<f32, [2, 4]> product ← a.matmul(b)
ثابت f32 mean ← product.media()
اعرض mean
}faber format --locale 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]
स्थिर टेंसर<f32, []> seed ← खाली
स्थिर टेंसर<f32, [2, 3]> a ← seed.strue(flat_a, [2, 3])
स्थिर टेंसर<f32, [3, 4]> b ← seed.strue(flat_b, [3, 4])
स्थिर टेंसर<f32, [2, 4]> product ← a.matmul(b)
स्थिर f32 mean ← product.media()
दिखाओ mean
}Faber — 10 lines in, 10 out (1.0×)
incipit {
fixum lista<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
fixum 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]
fixum tf32[] seed ← vacua
fixum tf32[2, 3] a ← seed.strue(flat_a, [2, 3])
fixum tf32[3, 4] b ← seed.strue(flat_b, [3, 4])
fixum tf32[2, 4] product ← a.matmul(b)
fixum f32 mean ← product.media()
nota mean
}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 format --locale 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 format --locale 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 format --locale th-TH — Thaiฟังก์ชัน divide(จำนวน a, จำนวน b) → จำนวน ⇥ ข้อความ {
ถ้า b ≡ 0 {
โยน "division by zero"
}
คืน a / b
}
เริ่ม {
ทำ {
บันทึก divide(10, 2)
}
จับ err {
เตือน err
}
}faber format --locale zh-Hans — Simplified Chinese函数 divide(整数 a, 整数 b) → 整数 ⇥ 文本 {
如果 b ≡ 0 {
抛错 "division by zero"
}
返回 a / b
}
入口 {
执行 {
显示 divide(10, 2)
}
捕获 err {
警告 err
}
}faber format --locale zh-Hant — Traditional Chinese函式 divide(整數 a, 整數 b) → 整數 ⇥ 文字 {
若 b ≡ 0 {
拋出 "division by zero"
}
傳回 a / b
}
入口 {
執行 {
註記 divide(10, 2)
}
捕捉 err {
警告 err
}
}faber format --locale 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 format --locale ar — Arabicدالة divide(عدد a, عدد b) → عدد ⇥ نص {
إذا b ≡ 0 {
ارم "division by zero"
}
أعد a / b
}
بداية {
افعل {
اعرض divide(10, 2)
}
التقط err {
نبه err
}
}faber format --locale hi — Hindiफलन divide(संख्या a, संख्या b) → संख्या ⇥ पाठ {
यदि b ≡ 0 {
इधरफेंको "division by zero"
}
लौटाओ a / b
}
आरंभ {
करो {
दिखाओ divide(10, 2)
}
पकड़ो err {
चेताओ err
}
}Faber — 13 lines in, 13 out (1.0×)
functio divide(numerus a, numerus b) → numerus ⇥ textus {
si b ≡ 0 ergo iace "division by zero"
redde a / b
}
incipit {
fac {
nota divide(10, 2)
}
cape err {
mone err
}
}Collections and iteration#
A list folded to a total with itera ex. The plainest possible read on how loops lower.
Faber source
faber format --locale en — English reader surfacefn summa(list<int> numeri) → int {
var int total ← 0
for from numeri const n {
total ← total + n
}
return total
}
main {
const list<int> valores ← [1, 2, 3, 4, 5]
print summa(valores)
}faber format --locale la — canonical Faberfunctio summa(lista<numerus> numeri) → numerus {
varia numerus total ← 0
itera ex numeri fixum n {
total ← total + n
}
redde total
}
incipit {
fixum lista<numerus> valores ← [1, 2, 3, 4, 5]
nota summa(valores)
}faber format --locale th-TH — Thaiฟังก์ชัน summa(รายการ<จำนวน> numeri) → จำนวน {
แปร จำนวน total ← 0
วน ออก numeri คงที่ n {
total ← total + n
}
คืน total
}
เริ่ม {
คงที่ รายการ<จำนวน> valores ← [1, 2, 3, 4, 5]
บันทึก summa(valores)
}faber format --locale zh-Hans — Simplified Chinese函数 summa(列表<整数> numeri) → 整数 {
变量 整数 total ← 0
遍历 取自 numeri 常量 n {
total ← total + n
}
返回 total
}
入口 {
常量 列表<整数> valores ← [1, 2, 3, 4, 5]
显示 summa(valores)
}faber format --locale zh-Hant — Traditional Chinese函式 summa(列表<整數> numeri) → 整數 {
變值 整數 total ← 0
遍歷 取自 numeri 定值 n {
total ← total + n
}
傳回 total
}
入口 {
定值 列表<整數> valores ← [1, 2, 3, 4, 5]
註記 summa(valores)
}faber format --locale vi — Vietnamesehàm summa(danh_sách<số> numeri) → số {
biến số total ← 0
lặp từ numeri hằng n {
total ← total + n
}
trả total
}
bắt_đầu {
hằng danh_sách<số> valores ← [1, 2, 3, 4, 5]
ghi_chú summa(valores)
}faber format --locale ar — Arabicدالة summa(قائمة<عدد> numeri) → عدد {
متغير عدد total ← 0
كرر من numeri ثابت n {
total ← total + n
}
أعد total
}
بداية {
ثابت قائمة<عدد> valores ← [1, 2, 3, 4, 5]
اعرض summa(valores)
}faber format --locale hi — Hindiफलन summa(सूची<संख्या> numeri) → संख्या {
चर संख्या total ← 0
दोहराओ सेवन numeri स्थिर n {
total ← total + n
}
लौटाओ total
}
आरंभ {
स्थिर सूची<संख्या> valores ← [1, 2, 3, 4, 5]
दिखाओ summa(valores)
}Faber — 12 lines in, 12 out (1.0×)
functio summa(lista<numerus> numeri) → numerus {
varia numerus total ← 0
itera ex numeri fixum n {
total ← total + n
}
redde total
}
incipit {
fixum lista<numerus> valores ← [1, 2, 3, 4, 5]
nota summa(valores)
}---