Language specification

What Avin is — a natively compiled, garbage-collected application language with a small type system and a light, indentation-based syntax.

Avin is a compiled, garbage-collected application language: expression-oriented code, algebraic data, pattern matching, first-class functions, rich immutable collections, classes and traits with real subtyping, built-in actors and state machines, and type inference, with a deliberately small type system. Its syntax is light and quiet: indentation marks blocks, functions are often a single name(params) = expression line, and match reads top to bottom as a list of cases.

Avin owns its whole runtime, so its generics are reified, values stay unboxed in containers, absence is an explicit Option, equality is typed, string is a built-in type, and failures are values. The design choices chapter lists each choice and what it means.

Principles

  1. Native and fast. Whole-program compilation through LLVM; generics are monomorphized; values that need no identity are not boxed. A feature whose cost is invisible at the call site needs a reason.
  2. Reified types. Every type that exists at compile time exists at run time; a type test never lies.
  3. Nominal. A type conforms to a trait or class because it says so, never because its member names happen to match.
  4. Two failure channels. A failure a correct caller can meet is a value (Result, Option); a bug is a trap. There is no null and there are no exceptions.
  5. Library, not compiler. println, collections, formatting and the rest are ordinary Avin code in the standard library. The compiler knows only the built-in types and a declared set of intrinsics.
  6. Sysl is the system layer. Avin reaches Sysl — and through Sysl, C — with bindings written in Avin. The standard library is written in Avin.

Chapters

ChapterContents
The AVIN philosophyAbstraction, Versatility, Intuition and Naturalness: the principles behind the design
Design choicesThe choices that shape the type system, runtime and library
TypesBuilt-in types, numbers, strings, tuples, functions, Any/Nothing
DeclarationsNames in any script, data, class, trait, object, impl, members, modules, initialization
Generics and inferenceReification, bounds, variance, type tests, local inference
Union typesUnions written in annotations: syntax, normal form, injection at a single site, match by type, ? combining errors, layout
Refined variantsVariants that fix their type’s arguments (IntLit(value: int) -> Expr[int]), arms that learn them, hidden type parameters, coverage of the variants possible at a type
Equality, identity and memory==, ===, hashing, display, values vs references, GC
ThreadsStarting and joining, sharing, synchronization, the memory model
Actors and state machinesactor and machine declarations, typed messages and Sendable, tell and ask, supervision, lifecycle, scheduling, states and transitions
ErrorsResult, Option, ?, traps
CollectionsThe Iterable hierarchy, arrays, literals, ranges, for
Sysl bindingsCalling Sysl from Avin
C bindingsCalling C libraries directly: prototypes checked against headers, handles, buffers, callbacks
Operators and control flowOperators, blocks, if, while, match
Call-by-namevalue: -> T parameters
Contextual parametersgiven values and using parameters: a context carried through calls, resolved lexically and coherently, never a conformance
Strings and formattingInterpolation and format specifiers
System libraryavin.process — arguments, environment, exit; avin.io — IoError, standard input; avin.fs — files and directories; avin.time (its own chapter below); avin.math — the elementary functions on real; avin.random — seeded and platform-seeded pseudo-random numbers; the environment, commands and pipelines, Source, avin.net (TCP, URLs, HTTP) and futures’ additions
Dates and timesavin.time: Instant, Duration, Date, Time, DateTime, Zone, Zoned and Period; the wall and monotonic clocks, calendar and zone arithmetic, ISO 8601 text and patterns
Regular expressionsavin.regex: the pattern language, leftmost-first backtracking, Regex, Match and MatchIterator, replacing and splitting
JSONThe package dev.avinlang.json, outside the standard library: depending on it, and what import avin.json says
Packagesavin.hocon, dependencies, version selection, avin.sum, workspaces, avin new and avin tidy, features, members of a repository, vendoring and the standard library’s modules
DerivationLibrary-defined derives: shapes of data types and classes, derive templates, annotations, a JSON library written with them
User interfacesThe ui package: syslui’s views, controls and signals and syslui-sdl’s window and frame loop, bound for Avin; drawing and tapping a tree with no window
Settled decisionsEvery decision made so far, in one list

The syntax is light and regular: blocks by indentation, functions as name(params) -> T, match written after the value with -> arms, generics as [T: Bound], conformance as impl Trait for Type, and classes, objects and variance in the same style.

Pages

  • The AVIN philosophy — Abstraction, Versatility, Intuition and Naturalness — the four principles that guide Avin's design.
  • Design choices — The choices that shape Avin's type system, runtime and library, and what each one means for a program.
  • Types — Built-in types, numbers, strings, unit, tuples, functions, and the top and bottom types.
  • Declarations — Names, data, class, trait, object, impl, members, modules and initialization.
  • Generics and inference — Reified, monomorphized generics with bounds and declaration-site variance; constructor parameters and the standard Functor and Monad traits; local type inference with subtyping.
  • Refined variants — Data variants that fix their type's arguments, and match arms that learn those arguments, so a typed interpreter, a typed protocol or a typed plan of transitions checks at compile time.
  • Union types — A | B written in annotations: an anonymous tagged sum, made at a single site, taken apart by match, and the way ? combines distinct errors.
  • Equality, identity and memory — Typed equality, identity only where it exists, Display and Debug, and the garbage-collected heap.
  • Threads — Starting and joining threads, what they share, how they synchronize, and what a racing read sees.
  • Errors — Recoverable failure is a value; a bug is a trap. No exceptions, no null.
  • Collections — A rich collection library with precise result types from first-order generics, where Iterator is Iterable and arrays are ordinary collections.
  • C bindings — Avin calls a C library directly, through bindings written in Avin whose C prototypes clang checks against the library's own headers.
  • Sysl bindings — Avin calls Sysl through bindings written in Avin; the compiler generates the Sysl side and lets Sysl check it.
  • Operators and control flow — Sysl's operator set and precedence, comparison chains, blocks that yield values, if, while, match and return.
  • Call-by-name — Parameters written value -> T are evaluated on each use, never at the call and never cached.
  • Contextual parameters — given values and using parameters carry a context — a transaction, a logger, a request — through the calls that need it, resolved lexically at compile time.
  • Strings and formatting — String literals, interpolation as a method call on StringContext, user-defined interpolators, and formatting through Display and Debug.
  • System library — The standard library's modules for the world outside the program — its process, files and the rest — written in Avin over Sysl bindings.
  • Dates and times — `avin.time`: eight types that keep the timeline, the calendar and the zone apart — `Instant`, `Duration`, `Date`, `Time`, `DateTime`, `Zone`, `Zoned` and `Period` — the two clocks, arithmetic across month ends and daylight saving, ISO 8601 text and patterns.
  • Packages — avin.hocon, dependencies by git, path and workspace, version selection, avin.sum, workspaces, features, machines and files for one machine, members of a repository, vendoring, a program of one file's dependencies header, the standard library's modules, and the commands that make and keep them.
  • Derivation through shapes — Library-defined derivation, where the compiler describes each data type and class as a shape, and a trait's own module says once how to derive it, checked at compile time and compiled per type.
  • Regular expressions — `avin.regex`: the pattern language, backtracking matching with leftmost-first results, `Regex`, `Match` and `MatchIterator`, replacing and splitting, and a regex as an extractor pattern.
  • Actors and state machines — `actor` and `machine` declarations: typed messages, what may be sent and how the compiler checks it, `tell` and `ask`, supervision of a trap, lifecycle and watching, scheduling on a pool, routers and topics, and states with transitions and stashed messages.
  • User interfaces — The ui package — syslui's views, controls and signals, and syslui-sdl's window and frame loop, bound for Avin; drawing and tapping a tree with no window.
  • JSON — JSON is the package dev.avinlang.json, not a module of the standard library: depending on it, and what an import of avin.json says.
  • Settled decisions — Every language and project decision made so far, in one terse list — settled and open.

Search

Esc
↑↓ to navigate ↵ to open Esc to close