LEVIATHAN v962456e · 962456eee1

leviathan-lang.com / docs / learn

Learn Leviathan

A guided tour of the language, front to back, from a one-line program to a shipped project.

A guided tour of the language, front to back. We start with a one-line program and finish by shipping a real project, picking up types, classes, pattern matching, error handling, and concurrency along the way. Every snippet is real Leviathan and is run by the documentation build, so what you read is what the compiler does. Read top to bottom, or jump to a chapter from the list below.

One idea to hold onto

Leviathan chases a single conviction: most of what looks like a language's "special case" is really a general rule nobody bothered to find yet. A constructor is just a method with a keyword; an operator is just a method named with a symbol; a property is just a typed view over a slot. Once you see the rule, the whole language gets smaller. Watch for it as we go.

In this tutorial

  1. Hello, Leviathan — Write and run the smallest useful program, and meet the compiler and the build driver.
  2. Values and types — Static types, inference with var and let, methods on primitives, string interpolation, and const.
  3. No null: optionals — Absence as a typed value, the ?? and ?. operators, and narrowing by flow typing.
  4. Collections — Arrays, maps, and sets as pure values; iterating with for..in; lazy pipelines with Seq.
  5. Classes and objects — Members, constructors, labeled constructors, operators, and get/set properties.
  6. Interfaces and multiple inheritance — Interfaces that require fields, multiple inheritance, and resolving collisions with distinct.
  7. Value types: structs and enums — Structs copied on every bind, mutating methods, and enums with a closed set of members.
  8. Pattern matching — Dispatching on values, ranges, types, and enum members with match.
  9. Errors and resources — Expected absence as a value, programmer errors as exceptions, and deterministic cleanup with using.
  10. Functions, generics and injection — Functions and methods, named and default arguments, generic inference, and bind/inject.
  11. Concurrency — Honest promises, await, workers for real parallelism, and where channels and task groups fit.
  12. A taste of metaprogramming — Compile-time folding with comptime, typed attributes, and rules that generate code.
  13. Shipping a project — Describe a project with trident.toml, then check, run, and build it with trident.