vyrn

Values and types

Numbers state their width. Text is UTF-8 bytes. A type can carry the rule that makes a value valid, and the compiler checks the rule where it can.

Numbers

Every number type states its width: Int8, Int16, Int32, Int64, the unsigned pairs, Float32 and Float64. There is no unsized Int, because its width would then depend on the machine.

A conversion is written. Int64(x) widens, and nothing widens on its own.

small 100 widened 101 count 9007199254740993 ratio 0.300000 flag true

Text

A String is UTF-8 bytes. byteLength is a field and counts bytes; charCount() walks the string and counts characters. The two agree on ASCII and disagree everywhere else, and the names say which one you asked for.

std/strings has the rest: split, join, trim, case, search, pad.

upper ADA bytes 6 chars 5 parts 3 rejoined a + b + c

Validated types

A where clause is part of the type. Age(30) is proven while the file compiles, so no check is emitted. Age(5) is refused by the compiler, in the same way a type error is refused.

Input from outside the program is not a constant, so it gets the total form. Age?(n) answers Option<Age>: Some when the rule holds, None when it does not. Nothing traps, and you cannot forget a check you never wrote.

The rule is readable by the compiler as well as by you. Chapter 9 turns the same declaration into a JSON Schema document.

ok 30 admitted at 25 refused at 5