Renderingen-US

Types and widths

Types come before names. string name, never name: string.

Everyday types#

fn nihil_agit() → void {
    print "done"
}

main {
    const string name ← "Marcus"
    const i32 aetas ← 30
    const bool ready ← true
    const list<int> empty ← empty
    const int ∪ none missing ← null
    print name, aetas, ready, empty, missing
    nihil_agit()
}
TypeIs
stringtext
i32a signed integer
booltrue / false — true / false
voidthe return type of a function that yields no value
noneabsence — the other half of an optional

Do not confuse void with empty. void is a type, used as a return annotation. empty is a value: the empty collection, which is why it seeds lists and tensors above. Binding empty to something that is not a collection is a compile error.

Numeric widths#

Name the width in type position. These are the numeric types — the same list as Math in the ether.

reader locale
faber convert --to en — English reader surface
main {
    const i32 signed ← -7
    const u8 byte ← 255
    const f64 wide ← 1.5
    print signed, byte, wide
}
faber convert --to la — canonical Faber
incipit {
    fixum i32 signed ← -7
    fixum u8 byte ← 255
    fixum f64 wide ← 1.5
    nota signed, byte, wide
}
faber convert --to th-TH — Thai
เริ่ม {
    คงที่ i32 signed ← -7
    คงที่ u8 byte ← 255
    คงที่ f64 wide ← 1.5
    บันทึก signed, byte, wide
}
faber convert --to zh-Hans — Simplified Chinese
入口 {
    常量 i32 signed ← -7
    常量 u8 byte ← 255
    常量 f64 wide ← 1.5
    显示 signed, byte, wide
}
faber convert --to zh-Hant — Traditional Chinese
入口 {
    定值 i32 signed ← -7
    定值 u8 byte ← 255
    定值 f64 wide ← 1.5
    註記 signed, byte, wide
}
faber convert --to vi — Vietnamese
bắt_đầu {
    hằng i32 signed ← -7
    hằng u8 byte ← 255
    hằng f64 wide ← 1.5
    ghi_chú signed, byte, wide
}
faber convert --to ar — Arabic
بداية {
    ثابت i32 signed ← -7
    ثابت u8 byte ← 255
    ثابت f64 wide ← 1.5
    اعرض signed, byte, wide
}
faber convert --to hi — Hindi
आरंभ {
    स्थिर i32 signed ← -7
    स्थिर u8 byte ← 255
    स्थिर f64 wide ← 1.5
    दिखाओ signed, byte, wide
}
FamilyWidths
Signedi8 i16 i32 i64
Unsignedu8 u16 u32 u64
Decimald64
Unbounded integerinf
Floatingf16 bf16 f32 f64

Lists and tables#

reader locale
faber convert --to en — English reader surface
main {
    const list<int> numeri ← [1, 2, 3]
    const map<string, int> aetates ← { "Marcus": 30, "Julia": 28 }
    print numeri[0]
    print aetates["Marcus"]
    print numeri.length()
}
faber convert --to la — canonical Faber
incipit {
    fixum lista<numerus> numeri ← [1, 2, 3]
    fixum tabula<textus, numerus> aetates ← { "Marcus": 30, "Julia": 28 }
    nota numeri[0]
    nota aetates["Marcus"]
    nota numeri.longitudo()
}
faber convert --to th-TH — Thai
เริ่ม {
    คงที่ รายการ<จํานวน> numeri ← [1, 2, 3]
    คงที่ ตาราง<ข้อความ, จํานวน> aetates ← { "Marcus": 30, "Julia": 28 }
    บันทึก numeri[0]
    บันทึก aetates["Marcus"]
    บันทึก numeri.ความยาว()
}
faber convert --to zh-Hans — Simplified Chinese
入口 {
    常量 列表<整数> numeri ← [1, 2, 3]
    常量 映射<文本, 整数> aetates ← { "Marcus": 30, "Julia": 28 }
    显示 numeri[0]
    显示 aetates["Marcus"]
    显示 numeri.长度()
}
faber convert --to zh-Hant — Traditional Chinese
入口 {
    定值 列表<整數> numeri ← [1, 2, 3]
    定值 表格<文字, 整數> aetates ← { "Marcus": 30, "Julia": 28 }
    註記 numeri[0]
    註記 aetates["Marcus"]
    註記 numeri.長度()
}
faber convert --to vi — Vietnamese
bắt_đầu {
    hằng danh_sách<số> numeri ← [1, 2, 3]
    hằng bảng<văn_bản, số> aetates ← { "Marcus": 30, "Julia": 28 }
    ghi_chú numeri[0]
    ghi_chú aetates["Marcus"]
    ghi_chú numeri.độ_dài()
}
faber convert --to ar — Arabic
بداية {
    ثابت قائمة<عدد> numeri ← [1, 2, 3]
    ثابت جدول<نص, عدد> aetates ← { "Marcus": 30, "Julia": 28 }
    اعرض numeri[0]
    اعرض aetates["Marcus"]
    اعرض numeri.طول()
}
faber convert --to hi — Hindi
आरंभ {
    स्थिर सूची<संख्या> numeri ← [1, 2, 3]
    स्थिर तालिका<पाठ, संख्या> aetates ← { "Marcus": 30, "Julia": 28 }
    दिखाओ numeri[0]
    दिखाओ aetates["Marcus"]
    दिखाओ numeri.लंबाई()
}

list<T> holds many of one type. A map maps keys to values — the { "key": value } form above is inline JSON ascribed to a map type, not a separate map literal, which is why it uses : where Faber's typed construction uses =. Both take type holes and unions as their parameters:

reader locale
faber convert --to en — English reader surface
main {
    const list<string ∪ int> mixed ← [1, "two", 3]
    const _ inferred ← [1, 2, 3]
    print mixed, inferred
}
faber convert --to la — canonical Faber
incipit {
    fixum lista<textus ∪ numerus> mixed ← [1, "two", 3]
    fixum _ inferred ← [1, 2, 3]
    nota mixed, inferred
}
faber convert --to th-TH — Thai
เริ่ม {
    คงที่ รายการ<ข้อความ ∪ จํานวน> mixed ← [1, "two", 3]
    คงที่ _ inferred ← [1, 2, 3]
    บันทึก mixed, inferred
}
faber convert --to zh-Hans — Simplified Chinese
入口 {
    常量 列表<文本 ∪ 整数> mixed ← [1, "two", 3]
    常量 _ inferred ← [1, 2, 3]
    显示 mixed, inferred
}
faber convert --to zh-Hant — Traditional Chinese
入口 {
    定值 列表<文字 ∪ 整數> mixed ← [1, "two", 3]
    定值 _ inferred ← [1, 2, 3]
    註記 mixed, inferred
}
faber convert --to vi — Vietnamese
bắt_đầu {
    hằng danh_sách<văn_bản ∪ số> mixed ← [1, "two", 3]
    hằng _ inferred ← [1, 2, 3]
    ghi_chú mixed, inferred
}
faber convert --to ar — Arabic
بداية {
    ثابت قائمة<نص ∪ عدد> mixed ← [1, "two", 3]
    ثابت _ inferred ← [1, 2, 3]
    اعرض mixed, inferred
}
faber convert --to hi — Hindi
आरंभ {
    स्थिर सूची<पाठ ∪ संख्या> mixed ← [1, "two", 3]
    स्थिर _ inferred ← [1, 2, 3]
    दिखाओ mixed, inferred
}

Tensors#

A tensor carries an element type and a shape. empty seeds an empty one; strue builds a shaped tensor from flat values.

reader locale
faber convert --to en — English reader surface
main {
    const list<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    const tensor<f32, []> seed ← empty
    const tensor<f32, [2, 3]> m ← seed.from_flat(flat, [2, 3])
    print m.mean()
}
faber convert --to la — canonical Faber
incipit {
    fixum lista<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    fixum tensor<f32, []> seed ← vacua
    fixum tensor<f32, [2, 3]> m ← seed.strue(flat, [2, 3])
    nota m.media()
}
faber convert --to th-TH — Thai
เริ่ม {
    คงที่ รายการ<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    คงที่ เทนเซอร์<f32, []> seed ← เซตว่าง
    คงที่ เทนเซอร์<f32, [2, 3]> m ← seed.สร้างจากข้อมูลแบน(flat, [2, 3])
    บันทึก m.ค่าเฉลี่ย()
}
faber convert --to zh-Hans — Simplified Chinese
入口 {
    常量 列表<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    常量 张量<f32, []> seed ← 空集
    常量 张量<f32, [2, 3]> m ← seed.由扁平构造(flat, [2, 3])
    显示 m.均值()
}
faber convert --to zh-Hant — Traditional Chinese
入口 {
    定值 列表<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    定值 張量<f32, []> seed ← 空集
    定值 張量<f32, [2, 3]> m ← seed.由扁平建構(flat, [2, 3])
    註記 m.平均值()
}
faber convert --to vi — Vietnamese
bắt_đầu {
    hằng danh_sách<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    hằng ten_xo<f32, []> seed ← tập_rỗng
    hằng ten_xo<f32, [2, 3]> m ← seed.dựng_từ_phẳng(flat, [2, 3])
    ghi_chú m.trung_bình()
}
faber convert --to ar — Arabic
بداية {
    ثابت قائمة<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    ثابت موتر<f32, []> seed ← فارغ
    ثابت موتر<f32, [2, 3]> m ← seed.ابن_من_مسطح(flat, [2, 3])
    اعرض m.المتوسط()
}
faber convert --to hi — Hindi
आरंभ {
    स्थिर सूची<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    स्थिर टेंसर<f32, []> seed ← खाली
    स्थिर टेंसर<f32, [2, 3]> m ← seed.समतल_से_बनाओ(flat, [2, 3])
    दिखाओ m.माध्य()
}

Shape sugar#

tf32[2, 3] is sugar for tensor<f32, [2, 3]> — same type, shorter to read in a signature.

reader locale
faber convert --to en — English reader surface
fn medium(tf32[2, 3] m) → f32 {
    return m.mean()
}

main {
    const list<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    const tf32[] seed ← empty
    const tf32[2, 3] m ← seed.from_flat(flat, [2, 3])
    print medium(m)
}
faber convert --to la — canonical Faber
functio medium(tf32[2, 3] m) → f32 {
    redde m.media()
}

incipit {
    fixum lista<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    fixum tf32[] seed ← vacua
    fixum tf32[2, 3] m ← seed.strue(flat, [2, 3])
    nota medium(m)
}
faber convert --to th-TH — Thai
ฟังก์ชัน medium(tf32[2, 3] m) → f32 {
    คืน m.ค่าเฉลี่ย()
}

เริ่ม {
    คงที่ รายการ<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    คงที่ tf32[] seed ← เซตว่าง
    คงที่ tf32[2, 3] m ← seed.สร้างจากข้อมูลแบน(flat, [2, 3])
    บันทึก medium(m)
}
faber convert --to zh-Hans — Simplified Chinese
函数 medium(tf32[2, 3] m) → f32 {
    返回 m.均值()
}

入口 {
    常量 列表<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    常量 tf32[] seed ← 空集
    常量 tf32[2, 3] m ← seed.由扁平构造(flat, [2, 3])
    显示 medium(m)
}
faber convert --to zh-Hant — Traditional Chinese
函式 medium(tf32[2, 3] m) → f32 {
    傳回 m.平均值()
}

入口 {
    定值 列表<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    定值 tf32[] seed ← 空集
    定值 tf32[2, 3] m ← seed.由扁平建構(flat, [2, 3])
    註記 medium(m)
}
faber convert --to vi — Vietnamese
hàm medium(tf32[2, 3] m) → f32 {
    trả m.trung_bình()
}

bắt_đầu {
    hằng danh_sách<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    hằng tf32[] seed ← tập_rỗng
    hằng tf32[2, 3] m ← seed.dựng_từ_phẳng(flat, [2, 3])
    ghi_chú medium(m)
}
faber convert --to ar — Arabic
دالة medium(tf32[2, 3] m) → f32 {
    أعد m.المتوسط()
}

بداية {
    ثابت قائمة<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    ثابت tf32[] seed ← فارغ
    ثابت tf32[2, 3] m ← seed.ابن_من_مسطح(flat, [2, 3])
    اعرض medium(m)
}
faber convert --to hi — Hindi
फलन medium(tf32[2, 3] m) → f32 {
    लौटाओ m.माध्य()
}

आरंभ {
    स्थिर सूची<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    स्थिर tf32[] seed ← खाली
    स्थिर tf32[2, 3] m ← seed.समतल_से_बनाओ(flat, [2, 3])
    दिखाओ medium(m)
}

Vectors#

vector<T, N> is a fixed-width vector, with vf32[N] as its sugar. Build one by converting a literal — the conversion is what fixes the width.

reader locale
faber convert --to en — English reader surface
main {
    const vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ vector<f32, 4>
    print v
}
faber convert --to la — canonical Faber
incipit {
    fixum vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ vector<f32, 4>
    nota v
}
faber convert --to th-TH — Thai
เริ่ม {
    คงที่ vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ เวกเตอร์<f32, 4>
    บันทึก v
}
faber convert --to zh-Hans — Simplified Chinese
入口 {
    常量 vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ 向量<f32, 4>
    显示 v
}
faber convert --to zh-Hant — Traditional Chinese
入口 {
    定值 vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ 向量<f32, 4>
    註記 v
}
faber convert --to vi — Vietnamese
bắt_đầu {
    hằng vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ vectơ<f32, 4>
    ghi_chú v
}
faber convert --to ar — Arabic
بداية {
    ثابت vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ متجه<f32, 4>
    اعرض v
}
faber convert --to hi — Hindi
आरंभ {
    स्थिर vf32[4] v ← [1.0, 2.0, 3.0, 4.0] ↦ सदिश<f32, 4>
    दिखाओ v
}

Naming a type#

type gives a type another name.

reader locale
faber convert --to en — English reader surface
type Nomen = string

type Puncta = list<int>

main {
    const Nomen n ← "Marcus"
    const Puncta p ← [1, 2, 3]
    print n, p
}
faber convert --to la — canonical Faber
typus Nomen = textus

typus Puncta = lista<numerus>

incipit {
    fixum Nomen n ← "Marcus"
    fixum Puncta p ← [1, 2, 3]
    nota n, p
}
faber convert --to th-TH — Thai
ชนิดนามแฝง Nomen = ข้อความ

ชนิดนามแฝง Puncta = รายการ<จํานวน>

เริ่ม {
    คงที่ Nomen n ← "Marcus"
    คงที่ Puncta p ← [1, 2, 3]
    บันทึก n, p
}
faber convert --to zh-Hans — Simplified Chinese
类型 Nomen = 文本

类型 Puncta = 列表<整数>

入口 {
    常量 Nomen n ← "Marcus"
    常量 Puncta p ← [1, 2, 3]
    显示 n, p
}
faber convert --to zh-Hant — Traditional Chinese
型別 Nomen = 文字

型別 Puncta = 列表<整數>

入口 {
    定值 Nomen n ← "Marcus"
    定值 Puncta p ← [1, 2, 3]
    註記 n, p
}
faber convert --to vi — Vietnamese
kiểu_tên Nomen = văn_bản

kiểu_tên Puncta = danh_sách<số>

bắt_đầu {
    hằng Nomen n ← "Marcus"
    hằng Puncta p ← [1, 2, 3]
    ghi_chú n, p
}
faber convert --to ar — Arabic
نمط Nomen = نص

نمط Puncta = قائمة<عدد>

بداية {
    ثابت Nomen n ← "Marcus"
    ثابت Puncta p ← [1, 2, 3]
    اعرض n, p
}
faber convert --to hi — Hindi
प्रकार Nomen = पाठ

प्रकार Puncta = सूची<संख्या>

आरंभ {
    स्थिर Nomen n ← "Marcus"
    स्थिर Puncta p ← [1, 2, 3]
    दिखाओ n, p
}

Records#

class declares a record. Fields are type-first, like everything else.

class Persona {
    const string name
    const int aetas
}

main {
    const _ p ← Persona { name = "Marcus", aetas = 30 }
    print p.nomen, p.aetas
}

Related: Bindings · Conversions · Types and values