Design choices

The choices that shape Avin’s type system, runtime and library, and what each one means for a program.

Avin compiles whole programs to native code and owns its runtime, so its types, values and library are designed together. These are the choices that shape it, each with what it means for a program.

ChoiceWhat it means
Types are real at run timeEvery generic is monomorphized, and every heap object’s header names its exact type, type arguments included. A type pattern on a generic type is checked and sound, and generic code creates an Array[T] as easily as any other value.
Values stay unboxedList[int] stores ints directly. A value is boxed only where it becomes a trait or Any value, at that one site.
Absence is explicitA value that may be missing has type Option[T]. Every reference refers to an object, and every field is initialized before the object can be observed.
Equality is typed== compares two values of one type; comparing unrelated types is a compile error. Every value has == and a hash, so any value can be a map key: data types, tuples and built-ins by value, class instances by identity unless the class implements or derives Eq. Identity is also the separate ===, for types that have identity.
Printing is a traitA type is printable because it implements Display and Debug; data derives both. Output always shows the value.
string is built instring is a type of the language: UTF-8, immutable, and named simply string. Its methods live in Avin’s own core library.
char is a Unicode scalar valueOne char is one character of text, whatever its code point.
Array[T] is an ordinary collectionInvariant, contiguous, fixed length and mutable; elements are stored unboxed; == compares contents, and printing shows them.
Integers keep their width, and overflow trapsFixed-width integers keep their width through arithmetic (i8 + i8 is i8), and a result that does not fit stops the program. Wrapping and saturating arithmetic are written with their own operators.
Binary data is byteIntegers are signed and are for counting; byte is the octet that files, sockets and encodings are made of.
Failures are values; bugs are trapsA failure a correct caller can meet is a Result or Option, propagated with ?. A bug stops the program with a trap.
Overloading is resolved staticallyFunctions and methods may share a name when their parameter types differ. The compiler chooses the most specific overload from the arguments at compile time, and an ambiguous call is an error rather than a guess.
object holds module-wide stateAn object is an ordinary value, and the one place for state and functions that belong to a type rather than an instance.
Initialization is checkedA constructor assigns every field before self is used. Traits carry behaviour, not state. Module-level values and objects initialize before main, in dependency order, and the compiler rejects a cycle.
Objects are just dataAn object’s header holds its type and what the collector needs, nothing more: there is no lock in every object. Threads share the heap; synchronization is library code, and actors are built into the language.
Tuples and functions of any arityA tuple or function type may have as many elements or parameters as the program needs.
unit is an ordinary typeIt has one value, (), and works as a type argument at no cost.
One top type, AnyEvery type conforms to Any; value types reach it by boxing at that one site.
data is pure valueA data value has no identity, so the compiler chooses to store it inline or on the heap, and the program sees the same behaviour either way.
Conversions are written+ on strings joins two strings; numeric conversions are explicit (long(x)); interpolation formats any value.
Generic programming at compile timeDerivation (derives) and reified type tests give generic code what it needs, checked by the compiler.
Whole-program compilationThe program, its libraries and the standard library are compiled together. That is what makes reification, monomorphized generic methods and devirtualization possible.

Search

Esc
↑↓ to navigate ↵ to open Esc to close