On this page
Varc declarations and types
A declaration introduces an object, type, subtype, operation or other named entity. Varc uses the same nominal types and constrained subtypes as the other Verada syntaxes. Familiar C-family notation does not make structural typing or implicit widening universal.
Bindings, inference and renamings
let limit: Positive = 100;
var count: Natural = 0;
var left, right: Integer;
let capacity = 100;
var total = 0;
ref current: Integer = values[index];
These are declaration fragments. let is immutable; var permits assignment. A typed declaration can omit initialization only where its declaration kind and flow rules permit it. A declaration with no type requires an initializer. Inference uses the initial value's type; an untyped immutable static numeric value can be a named number rather than a general runtime object.
ref renames an existing object rather than copying it. The type annotation is optional when it can be inferred. Its target must be a legal renaming with a sufficient lifetime; ref is not a request for arbitrary Python-style sharing or a Rust borrow of any temporary.
A typed object can be aliased, for example var storage: aliased Integer = 0;. Access-taking still has lifetime/exclusivity rules. Aspects are annotations after the initializer/type and before the semicolon: var reading: Integer @Volatile; in an appropriate package context.
A declaration after an executable statement starts a nested scope running to the end of the current brace. The declaration is not hoisted above its initializer or made visible to earlier expressions. Finalization follows the resulting scopes.
Scalar and derived types
| Form | Meaning |
|---|---|
type Reading = range -1000...1000; |
Distinct signed integer type |
subtype Percent = Integer range 0...100; |
Constrained Integer subtype |
type Byte = mod 256; |
Modular type |
type Real = digits 6 range -1.0e6..=1.0e6; |
Floating-point type |
type Ratio = delta 0.01 range -1000.0..=1000.0; |
Ordinary fixed-point type |
type Money = delta 0.01 digits 12; |
Decimal fixed-point type |
type Metres = new Integer range 0..=1000; |
Derived type |
range, mod, digits and delta are contextual type words. Bounds, moduli, precision, rounding and conversions use the shared type rules. A subtype's range must lie within the subtype it constrains: subtype P = Positive range -5..=5; is B2002, and bounds known only at run time are a range check the prover must prove. Signed integers have finite base ranges. A subtype constraint does not create distinct nominal identity; a new type does.
A decimal fixed-point type (delta 0.01 digits 12) has a power-of-ten delta and 1 to 18 digits (decimal fixed point). A digits constraint gives a decimal subtype fewer digits and the range they span: subtype Price = Money digits 6; runs from -9999.99 through 9999.99. On a floating-point subtype a digits constraint, and a delta constraint anywhere, are the old forms and are rejected (B0904).
An enumeration uses:
enum State { Idle, Busy, Done }
A trailing comma and optional final semicolon are accepted. Character literals can also declare enumeration literals where legal. Literal resolution still requires a type context. Predefined Boolean uses True and False.
An enum whose variants carry fields is a data enum, as in Rust:
pub enum Shape {
Circle { radius: Natural },
Rect { width, height: Natural },
Empty,
}
Each variant is a function making a value, Circle(radius: 2) or Empty, and a match reads a value's fields by naming them, Circle { radius } =>, Rect { width: w, .. } => (see match). Underneath it is a record with a discriminant, kind, of the enumeration Shape_Kind (Circle, Rect, Empty), defaulting to the first variant so that a variable can change variants, and each variant's fields named after it (Circle_radius), which other syntaxes see. A field's type is a named subtype. A data enum is declared in a package, in a body, or at the top of a file of functions.
Arrays and constraints
type Four = [1...4]Integer;
type Values = [Positive..]Integer;
type Matrix = [Positive.., Positive..]Integer;
var samples: Values[5...7] = [1, 2, 3];
An array definition puts its index specifications in brackets, followed by the component type. [Index]T uses a constrained discrete subtype; [Index..]T leaves the bounds open. Each unconstrained dimension uses that form. Constraints on an object or subtype use a bracket suffix on the array type.
... and ..= both include the upper bound. samples has indices 5, 6 and 7.
[1..=3, 1..=3]T is one rank-two array, not an array of pointers to rows. Index it as matrix[i, j]. Its dimensions have independent bounds and rectangular shape. Element order, sliding assignment, zero-length arrays and shape checks are defined in composite types.
An anonymous array definition can appear directly in an object/component type. An aliased component marker follows the index brackets where supported. Use a named type when an API needs stable type identity or generic actual matching.
Structs and field visibility
struct Point {
x, y: Integer = 0,
}
A field has one or more names, a type, optional initializer, and optional annotations. Fields may end with comma or semicolon. A default initializes an individual component; it is not a class-level mutable Python object shared across all values.
At package scope, pub struct chooses a public API. Fields of a public struct are either all public or all hidden:
pub struct Point {
pub x: Integer,
pub y: Integer,
}
With every field marked pub, clients can see the public record representation. With no fields marked pub, extraction exposes a private type and keeps its representation hidden. Mixing public and hidden fields in the same struct is rejected (B0702); this frontend does not implement arbitrary per-field public/private layout in one public record.
Modifiers come before struct: limited struct, tagged struct and abstract tagged struct, in either form; pub tagged struct Account { ... } with no pub fields is a tagged private type. An alternative type definition uses type T = struct { ... }. An empty struct body represents a null record.
Discriminants and variants
A discriminant list follows the type name:
type Message(kind: Kind = Empty) = struct {
match kind {
Number => { value: Integer },
Empty => {},
}
}
This is a type-definition fragment assuming Kind with the stated enumeration literals. The match inside a struct is a variant part controlled by the discriminant; it is not a runtime executable match statement. Each alternative declares components present for that case. Ordinary fields can precede it.
Defaults permit the supported mutable-discriminant form. Access discriminants are excluded.
Discriminants also stand on private, incomplete and derived types:
pub type Buffer(<>) = private;
type Node(size: Natural);
type Filled(count: Positive) = new Buffer_Record[length: count];
type Polygon(sides: Positive) = new Shape with struct {
lengths: Values[1..=sides],
}
(<>) declares unknown discriminants: the full view, a pub(child) struct Buffer(n: Positive) { ... } in the package's private part, has its own, and outside the package an object of the type takes its value from its initial value. An incomplete type's completion repeats its discriminants. A derived type's own discriminants each constrain one or more of the parent's, alone, or the parent's are given values (type Row(length: Natural) = new Grid[rows: 1, columns: length];); a type extension's own discriminants that constrain none of the parent's come after the parent's fields. The rules are Vada's (records and discriminants). Component presence and constrained assignment remain checked; a branch that assumes a variant exists without establishing its discriminant can fail proof.
Private, limited, incomplete and tagged types
type Node;
type Handle = private;
type Resource = limited private;
type Shape = abstract tagged struct {};
type Circle = new Shape with struct { radius: Natural };
type Printable = interface;
These are declaration fragments. Incomplete/private views need appropriate completions. limited restricts copying and assignment. Tagged types support declared inheritance and dispatch; Shape::Class names a class-wide view. An extension can add interfaces using and Interface_Name before its optional with struct/with private extension.
Plain and limited interfaces are available; synchronized, task and protected interfaces are excluded.
Private representation is normally expressed by package extraction, including the all-hidden public struct rule. Low-level split/private type forms are useful for translation and advanced unit arrangements, but ordinary Varc packages need not maintain duplicate source definitions solely to imitate Vada's two-file layout.
Access and callback types
type Link = *Node;
type Reader = *fn(value: Integer) -> Integer;
type Action = not null *fn(value: inout Integer);
*Node is an owning access type in a type definition. *const Node expresses the supported constant-designating form; supported anonymous *T/*const T parameters and local objects serve borrowing/observation roles. not null excludes null at the relevant boundary.
*all T is a general access type: it designates an aliased object declared rather than allocated, under the general access rules. Callback types designate compatible library-level subprograms and can carry contracts. They are not closures; nested subprograms cannot be designated.
Allocation is new T or new T(initial-value). A type declaration does not itself allocate. See ownership forms.
Exceptions, package and operation renamings
exception Bad_Input;
exception Input_Error renames Bad_Input;
package Short renames Long.Package_Name;
fn visit(value: Integer) renames walk;
These are contextual fragments. Renaming preserves the entity rather than wrapping/copying it, so profiles and visibility must match. A user exception is separate from a failed check. A package renaming can also be a file of its own, short.va holding import Long_Package_Name; pub package Short renames Long_Package_Name;, which other units import as Short.
Representation clauses
The source forms parallel explicit annotations:
for Type::Size use expression;
for Enum use (Literal: Code, ...);
for Record_Type use record {
field at byte_position range first_bit..=last_bit;
}
record, at and range in these patterns are contextual words. These clauses are accepted for compatibility and do not change the layout Verada chooses; see representation clauses.
External object addresses use @Address(...) or the appropriate ::Address clause under the device restrictions. The old for X use at A; form is diagnosed as obsolescent rather than silently mapped to unrestricted address aliasing.
Declaration grammar map
object ::= ("let" | "var") names [":" object-type] ["=" expression] annotations ";"
renaming ::= "ref" name [":" object-type] "=" object-expression annotations ";"
type ::= "type" name [discriminants] ["=" definition] annotations terminator
subtype ::= "subtype" name "=" subtype-indication annotations ";"
struct ::= "struct" name [discriminants] annotations "{" fields [variant] "}" [";"]
enum ::= "enum" name annotations "{" literals "}" [";"]
definition ::= scalar | array | struct-definition | private | derived | interface | access
An untyped object requires initialization. Braced record definitions may omit a final semicolon; ordinary nonbraced type definitions require one. Generic formal type declarations have a distinct comma-delimited context described in the next chapter.