DEVELOPMENT EDITION · 769442725406
Language Reference
On this page

Types and scalar values

A type defines a set of values and permitted operations. Distinct named types have nominal identity: two declarations with the same representation need not be interchangeable. A subtype keeps the identity of an existing type while constraining its values. Type compatibility, initialization, and proof of value constraints are separate checks.

Type identity and subtype constraints

The following Vada fragments illustrate the distinction:

type Temperature is range -100 .. 200;
subtype Percent is Integer range 0 .. 100;

Temperature is a new signed integer type; using it where Integer is expected generally requires conversion. Percent is still Integer, with a narrower range checked at boundaries such as initialization, assignment, passing an argument, or returning a result. Constraints can also describe array bounds, discriminants, predicates, and null exclusion.

An empty range contains no values. It is useful as the bounds of a null array or an empty iteration, but cannot supply an ordinary scalar value satisfying that subtype. A constraint on a new signed type must be statically known. Supported subtype bounds may depend on runtime values; such bounds are evaluated as the subtype/object is elaborated.

Predefined scalar environment

Name Meaning in this implementation
Boolean The two values False and True, distinct from integer types
Character Latin-1 characters (256 positions)
Wide_Character, Wide_Wide_Character Unicode characters: the Basic Multilingual Plane (65,536 positions), and every code point
Integer Signed 64-bit base range, −2⁶³ through 2⁶³ − 1
Natural, Positive Integer subtypes starting at 0 and 1 respectively, up to 2⁶³ − 1
Short_Short_Integer, Short_Integer Distinct signed 8-bit and 16-bit types
Long_Integer, Long_Long_Integer Distinct signed 64-bit types
Long_Long_Long_Integer Signed 128-bit type
Float Binary32 floating-point presentation with 6 decimal digits
Long_Float Binary64 floating-point presentation with 15 decimal digits
Duration Ordinary fixed point with delta 10^-9, small 2^-30, and declared bounds -2^32 through 2^32 seconds

The language leaves Integer's range to the implementation (at least 16 bits); Verada's is 64 bits in all three syntaxes, so lengths, counts, indices and positions, which are Natural and Positive, are as large as memory. Where a program needs an exact width, Interfaces declares Integer_8, Integer_16, Integer_32 and Integer_64; for C, Interfaces.C.int is C's 32-bit int.

These names are declared in the predefined package Standard. In every syntax, Standard.Integer names the predefined type even where a local declaration of Integer hides it.

String is an unconstrained array of Character indexed by Positive, rather than a scalar. Vibe maps int to Integer, float to Long_Float, bool to Boolean, and str to the copyable Text library type. These are concrete Verada mappings, not Python's arbitrary-precision integer or object model.

The integer reference gives all exact integer bounds and the selected base widths for user-declared signed types. No pointer-size or host C int rule changes them.

Enumeration types

An enumeration declares an ordered set of literal values. The literal's position starts at zero in declaration order. Comparisons use that order. Character-literal enumerators are supported in the Ada presentation; enumerations with the same literal names are distinct types, and context or qualification resolves the intended literal.

type State is (Idle, Busy, Finished);

State'Pos(Busy) is 1; State'Val(1) yields Busy. Successor/predecessor operations must remain in the permitted range. An enumeration representation clause gives each literal the code it is stored as: 'Pos and the order are still the positions, and the codes are what memory holds, what 'Enum_Rep and 'Enum_Val give and take, and what Unchecked_Conversion reads (see representation clauses).

Boolean is not an integer subtype. An if condition or logical operation requires a Boolean value; Python-style truthiness and arithmetic on bool are not shared-language rules.

Modular arithmetic

A modular type has values from zero through one less than a static modulus. Verada accepts moduli from 1 through 2^128. Addition, subtraction, and multiplication have deliberate modular behavior rather than signed-overflow failure. This does not remove division-by-zero, index, conversion, or other checks in expressions involving modular values.

Bitwise operations apply only to supported operand types; they are not interchangeable with short-circuit Boolean operations. A modulo type does not implicitly convert signed integers of unrelated types. Use explicit conversions when changing the domain, and prove their required constraints. T'Modulus reports the declared modulus.

Floating point

A user floating type declares a static decimal digits value from 1 through 15. Values up to 6 choose binary32; values from 7 through 15 choose binary64. An optional declared range adds a first-subtype constraint. A new declaration retains distinct type identity even if it selects the same IEEE format as another type.

Executable arithmetic uses the selected floating representation and rounding; a mathematical real-number model is a different domain. Overflow and finite-value obligations remain relevant. Do not rely on producing infinities or NaNs as a way to bypass a checked operation. Signed zero, rounding, cancellation, and conversion can affect results even when values remain within a declared range. A successful proof does not mean the rounded result equals an exact rational expression unless the contract actually establishes that relationship.

Static real expressions are evaluated as exact rational expressions before their concrete destination representation is chosen. In particular, arithmetic consisting only of float literals can differ from CPython's rounding after every operation.

In Vibe, / is Python's true division: it always yields a float, so 7 / 2 is 3.5, and // is floor division of integers. Vada and Varc / on integers truncates toward zero (see integer ranges).

Floor, Ceiling, Rounding, and Truncation are floating-type attributes. They return values in that floating type; a conversion to an integer type is a separate operation. Ordinary real-to-integer conversion rounds to nearest, with halves away from zero. Vibe's recognized int(value) helper deliberately truncates a floating value toward zero instead.

Ordinary fixed point

An ordinary fixed-point declaration requires a static positive delta and a range. The implementation selects Small as the largest power of two no greater than the delta. Executable values are multiples of that small. Delta expresses the requested resolution; it is not a guarantee of decimal-exact arithmetic for arbitrary decimal input.

type Fraction is delta 0.125 range -8.0 .. 8.0;

Addition and subtraction use the fixed type. Multiplication/division by supported integer operands use the fixed domain. A product or quotient of two fixed values requires the appropriate expected fixed result type or an explicit conversion so the result's scale is determined. A real literal used directly as an operand of fixed multiplication/division has explicit restrictions; give it a fixed type first, for example Fraction'(0.5).

Small, Delta, and Aft expose fixed-type properties. Duration is a predefined ordinary fixed-point type used for time intervals.

Decimal fixed point

A decimal fixed-point type counts in exact steps of a power of ten, as money does:

type Money is delta 0.01 digits 12;

The delta must be a power of ten (1.0, 0.1, 0.01, ...) and digits a static integer from 1 through 18; anything else is B2003. Small equals the delta, so every value is an exact multiple of it, and the range is ±(10^digits − 1) × delta unless a range narrows it: Money runs from −9,999,999,999.99 through 9,999,999,999.99. The arithmetic is the fixed-point arithmetic above, and a result that falls between two steps is truncated toward zero, so Money'(59.97) / 2 is 29.98. Overflow and range checks are proved as for any other numeric type. Money'Digits is 12 and Money'Scale 2, and Money'Round (X) rounds a real value to the nearest cent, halves away from zero, where Money (X) truncates. A subtype with a digits constraint has fewer digits, and the range they span unless a range follows: subtype Price is Money digits 6; runs from −9,999.99 through 9,999.99 and Price'Digits is 6. It cannot have more digits than the subtype it constrains (B2002). A generic formal type D is delta <> digits <>; (Varc generic<type D = delta <> digits <>>) takes any decimal type.

Vibe has no fixed-point declaration: declare ordinary or decimal fixed-point types in a Vada or Varc package, and import them.

Static expressions and named numbers

Integer and real literals initially have universal numeric meaning. Expected type context resolves them to concrete types. Compile-time arithmetic can use arbitrary-precision integers and exact rationals, but a value used as a concrete runtime type must fit that type. A literal too large for Integer does not become a big integer merely because the compiler could represent it while processing the source.

A named number is a constant compile-time numeric expression without a concrete object type. An initialized constant object is different: it has a concrete subtype and value. Static contexts include new signed bounds, moduli, floating digits, fixed deltas, and other forms requiring compile-time values. A nonstatic value in such a position produces B2003.

Conversion and qualification

A conversion T(X) requests a value in a permitted target type. It requires related or otherwise supported source/target categories, may round, and introduces range/predicate/null checks as appropriate. It does not retroactively change the type of the arithmetic that computed X. Convert an operand before an operation when a wider intermediate is required.

A qualification, Vada T'(X), fixes the expected type of an expression or aggregate without requesting an unrelated value conversion. It can resolve overloaded literals, operators, function results, and aggregates. Varc and Vibe expose their supported construction/conversion forms in their syntax references; identical parentheses do not make every Python constructor an accepted conversion.

Array conversion and assignment have separate shape/sliding rules. Tagged/class-wide conversions may require a runtime tag check. Access conversions are constrained by ownership and accessibility. A generic “cast” cannot escape these rules.

Unchecked conversion of bits

An instance of Ada.Unchecked_Conversion reads a value's bits as a value of another type. Verada models it exactly between scalar types stored in the same number of bits (integer, modular, enumeration and floating-point types): an Integer_32 of -1 converts to the Unsigned_32 16#FFFF_FFFF#, a Float of 1.5 to 16#3FC0_0000#, and back. Where not every pattern of bits is a value of the target (a range narrower than its storage, an enumeration with fewer literals, a float's NaNs and infinities), the conversion checks that these bits are one, and the prover proves that check like any range check. Both types must be scalar types stored in the same number of bits; scalars of different sizes are rejected (B2027), and Verada does not reinterpret the bits of records or arrays.

function To_Bits is new Ada.Unchecked_Conversion (Float, Interfaces.Unsigned_32);
function From_Bits is new Ada.Unchecked_Conversion (Interfaces.Unsigned_32, Float);
...
pragma Assert (To_Bits (1.5) = 16#3FC0_0000#);
X := From_Bits (W);  --  checked: W's exponent field is not all ones

Private, incomplete, and limited types

A private type separates its public view from its full representation in the package's private part. Clients can declare values and call permitted operations without accessing hidden components. A full view must complete the public declaration conformingly. An incomplete declaration introduces a type name for a later completion, useful for recursive owned structures; it does not permit creating an object of an unknown layout.

A limited type cannot be copied or freely assigned. Supported construction and result forms must build it in place. A type containing limited components inherits the relevant restrictions. Reclaimed limited values and copyable reclaimed values have additional resource rules described in ownership.

Mathematical numeric models

Ada.Numerics.Big_Numbers.Big_Integers and Big_Reals provide model types useful in contracts. Executable big integers have arbitrary precision, as their proof model does: only memory limits a value (Storage_Error when it cannot hold a result). Big reals are rational models, not a promise of arbitrary real-number computation without cost or bounds.

Use library operations and their contracts to cross domains. Converting a big integer to Integer requires that it fits; describing a machine result using a ghost model does not remove the machine arithmetic's overflow obligations. Container functional models similarly describe values rather than changing executable storage.

For exact operator syntax and literal spellings, use Vada, Varc, or Vibe. For concrete numeric properties, use the attribute catalog and limits.