Skip to main content

Language Reference — Overview

This section is the normative description of Verum's language surface. Where this section and the grammar reference disagree, the grammar wins — but they should not disagree. Everything documented here has a production in the grammar.

If you want the whirlwind tour, read Getting Started → Tour. If you want the machinery behind a feature, this is the place.

The concentric layers of the language

Verum's concrete syntax stacks in six conceptual layers. Every layer is independent, and every layer adds a precise kind of meaning.

LayerNameRepresentative forms
6Proof DSLtheorem, lemma, tactic, calc, forall, exists
5Metameta fn, quote { … }, @-macros, @cfg, splices
4Effects & Capabilitiesusing [...], with [...], throws, @verify
3Memory&T, &checked T, &unsafe T, CBGR
2Typesrefinement, dependent, protocol, HKT, generics
1Expressionscontrol flow, pattern matching, closures, comprehensions
0Lexicalliterals, identifiers, operators, 3 reserved keywords

You can write Verum at any layer. Layer 0–1 alone gives you a clean expression-oriented systems language. Add layer 2 for stronger types. Add layer 4 for explicit effect tracking. The top two layers are opt-in — you pay only for what you use.

Pages in this section

Lexical & syntactic structure

  • Syntax — the lexical and syntactic shape of a Verum program. Keywords, literals, operators, top-level items.
  • Tagged Literalssql#, json#, rx#, and ~40 other tags with compile-time validation.

The type system

  • Types — the type grammar: primitives, records, variants, tuples, functions, generics.
  • Refinement Types — predicate subtyping, checked by SMT at compile time.
  • Dependent Types — Σ, Π, path types, index refinements, value-dependent generics.
  • Protocols — Verum's interfaces. Methods, associated types, GATs, specialisation, negative bounds.
  • Generics — type parameters, bounds, kind annotations, rank-2 functions, HKT, universe polymorphism.
  • Type Properties — compile-time type metadata: T.size, T.alignment, T.name.
  • Capability TypesDatabase with [Read], type-level access-control attenuation.

Code organisation

  • Functions — definitions, modifiers (pure, meta, async, cofix, unsafe), generators (fn*), throws, using, where ensures.
  • Patterns — the full pattern grammar. Literals, wildcards, variants, records, slices, ranges, is type tests, or/and patterns, guarded patterns.
  • Active Patterns — user-defined pattern matchers: total Even(), parameterised InRange(0, 100)(), partial ParseInt()(n).
  • Destructuring — patterns on the left of let, assignment, parameters; let else, if-let chains.
  • Comprehensions — list, stream, map, set, generator. Unified clause syntax.
  • Quantifiersforall and exists expressions for specifications and proofs.
  • Copatterns & Coinductioncofix functions, infinite data via observations, productivity.

Memory

  • Memory Model — ownership, moves, borrowing, lifetimes, generation tags.
  • References — the three-tier reference system &T, &checked T, &unsafe T.
  • CBGR — Capability-Based Generational References: the runtime machinery behind tier 0.

Modules & contexts

  • Modulesmount, visibility levels, coherence, cogs.
  • Context Systemusing [...] dependency injection; negative, conditional, transformed, named contexts; context groups.

Computation

  • Async & Concurrencyasync / await, select, nursery, spawn, yield, for await, stream combinators, structured concurrency.
  • Error HandlingResult, typed throws, try/recover/finally, defer / errdefer, let else.
  • Metaprogrammingmeta fn, quote { ... }, N-stage splicing, token trees, user-defined macros via @-prefix.
  • Proof DSL — theorems, lemmas, tactics, calculational proofs, by auto / by smt.

Boundaries

  • Attributes@derive, @verify, @repr, @cfg, @specialize, and the full attribute vocabulary.
  • FFIextern "C" blocks, ffi { ... } with memory effects, thread safety, error protocols, ownership.

Relating pages to grammar

Every page in this section is paired with one or more grammar productions. For quick jumps:

FeaturePageGrammar section
Lexical layerSyntax, Tagged Literals§1 (lexical grammar)
Core typesTypes§2.3, 2.8
Refinement predicatesRefinement Types§2.3 (type_refinement)
Σ / Π / path typesDependent Types§2.3 (sigma_bindings, path_type)
ProtocolsProtocols§2.5 + 2.18
Generics, boundsGenerics§2.4 + 2.4.x
T with [Read]Capability Types§2.8 (capability_type)
FunctionsFunctions§2.4
Pattern grammarPatterns§2.14
Active patternsActive Patterns§2.14 + 2.14.1
forall / existsQuantifiers§2.19.9
Comprehensions & streamsComprehensions§2.10, 2.11
CopatternsCopatterns§2.4 (copattern_body)
Three-tier referencesReferences, CBGR§2.8 (managed/checked/unsafe ref)
Modules and visibilityModules§2.1, 2.2
Context systemContext System§2.4, 2.6
Async, nursery, selectAsync & Concurrency§2.12.1, 2.12.2, 2.12.3
try / recover / finallyError Handling§2.12.1, 2.13
meta fn, quote, splicesMetaprogramming§2.4, 2.12.0.1, 2.16
Theorems, tactics, calcProof DSL§2.19
@derive, @verify, etc.Attributes§2.1 (attribute_item)
FFIFFI§2.7

Core vocabulary

TermMeaning
ItemTop-level declaration: function, type, implement, const, module, context, protocol, FFI, impl of an attribute.
RefinementA predicate attached to a type. Every value of the type must satisfy it; verified by SMT at compile time.
ProtocolAn interface: a set of method and associated-type signatures. Implemented with implement ... for ....
ContextA typed capability injected into a function via using [...]. Explicit; no hidden globals.
CapabilityA type-level permission: T with [Read, Write] narrows what can be done with T.
CogA package — a distributable unit of Verum code with a Verum.toml manifest.
TierA level in the three-tier reference model: &T (tier 0), &checked T (tier 1), &unsafe T (tier 2).
CBGRCapability-Based Generational References — the default memory-safety mechanism. ~15 ns per dereference.
VBCVerum ByteCode — the language's unified IR, interpreted or compiled to native via LLVM.
StageMetaprogramming tier: 0 = runtime, 1 = first meta, N = meta-meta-… Each quote targets stage N − 1.

Reading conventions

  • verum fenced blocks are illustrative — some may elide context clauses or refinements for clarity. Complete examples are marked // complete in the code comment.
  • Grammar snippets (in EBNF) are verbatim fragments of the grammar reference.
  • indicates compilation or evaluation direction.
  • indicates a type-checking judgement.
  • Layer annotations (layer 2) on a feature indicate where in the six-layer stack it lives.

Three ways to enter the section

The pages cross-reference; there is no strict linear order.

A smallest well-formed program per layer

Layer 0–1 only — an expression

fn main() using [IO] {
print("hello, world");
}

Add layer 2 — refined types

type NonNegative is Int { self >= 0 };

fn double(n: NonNegative) -> NonNegative { n * 2 }

Add layer 3 — references

fn sum(xs: &List<Int>) -> Int {
let mut acc = 0;
for x in xs { acc += x; }
acc
}

Add layer 4 — effects

fn read_config(path: &Path) -> IoResult<Config>
using [FileSystem]
where throws(IoError)
{
let text = fs::read_to_string(path)?;
Config.parse(&text)
}

Add layer 5 — meta

meta fn derive_serialize<T>() -> TokenStream {
let fields = @type_fields<T>();
quote {
implement Serialize for $T {
fn write(&self, out: &mut Writer) {
$[for f in fields { out.write(self.${f.name}); }]
}
}
}
}

Add layer 6 — proof

theorem double_monotone(a: Int, b: Int)
requires a <= b
ensures 2 * a <= 2 * b
{
proof by omega
}

Every program — from print("hi") to a certified ledger — is the composition of a subset of these six layers. Master them in any order; revisit the others when the problem demands it.

Ready?

Start with Syntax.