Renderingen-US

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

reader locale
faber format --locale en — English reader surface
main {
    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 Faber
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 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 — Vietnamese
bắ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

reader locale
faber format --locale en — English reader surface
fn divide(int a, int b)  intstring {
    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 Faber
functio divide(numerus a, numerus b)  numerustextus {
    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 — Vietnamese
hà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)  numerustextus {
    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

reader locale
faber format --locale en — English reader surface
fn 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 Faber
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)
}
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 — Vietnamese
hà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)
}

---

All lanes · Measured support per term