Zane Types
This document specifies Zane’s data types: fundamental, value, and reference types; the # modifier; fields; constructors; type and alias declarations; and the init{ } expression. Methods and other behavior live in functions.md.
See also:
memory.md§2 for ownership rules.functions.mdfor methods and functions.syntax.md§1 and §3 for declaration grammar.
1. Overview
Zane keeps data layout and construction separate from behavior.
Fields-only type bodies. A type body declares storage only — no methods or constructors live inside the body.One kind axis. A type is a value type unless its mould is marked#, which makes it a reference type — identity-bearing, aliasable through&, able to hold reference-type and&fields, and moved rather than copied.structis a value mould;#structa reference mould. Either kind may recurse (seeadt.md§4).Package-scope constructors. A constructor is a verb at package scope, and every mould may declare one. Astructconstructor builds the value withinit{ }; anenumconstructor returns a member, and avariantconstructor returns a case.Name-based field privacy. A leading_makes a field private to the package that declares its type.Strings are values.Stringand its storage primitive own their bytes and copy deeply. Interpolated literals remain string concepts (§2.7–§2.8). The string primitive reads and writes numbers (§2.10–§2.11) and reads its own bytes (§2.12).Fundamental and declared types.Int,Float,I32,F32,U8,Bool,String,Unit,Array,ArrayRef,List, andListRefare types that thecorepackage declares over storage primitives;typeintroduces a new distinct named type andaliasan interchangeable name.
2. Value and Reference Types
2.1 The value/reference axis and the # modifier
Every mould is a value mould unless it is marked with #, which makes it a reference mould; these are its value form and its reference form. A type declared with a value mould is a value type; one declared with a reference mould is a reference type. The compiler instead fixes whether an intrinsic type is a value type or a reference type: the scalar primitives @primitives$I32, @primitives$I64, @primitives$F32, and @primitives$F64, @primitives$U8, @primitives$Bool, @primitives$String (§2.7), @primitives$Array<T, n>, and @primitives$List<T> are value types, and @primitives$ArrayRef<T, n>, @primitives$ListRef<T> (generics.md §8), and the runtime types (effects.md §6.6) are reference types. This value/reference axis is orthogonal to the shape of the mould (such as a product struct or a sum variant, see §2.5). For the product shape, struct is the value mould and #struct the reference mould. The # mark applies only to a mould — #struct, #variant, or #enum (see adt.md §2 and §3 for #enum and #variant) — or to a foreign handle, #handle, which has no value form (ffi.md §4.1), and only where a type is declared (§5.3). A reference type is a distinct type from any value type; it reuses only the field layout of its mould and otherwise has its own identity, its own constructors, and its own methods (see memory.md §2).
A value type is copied on assignment, has no identity, and is transitively a value: it may contain only other value types, never a reference-type or & field (§2.2, memory.md §2.10). A reference type has single ownership and stable identity, follows the rules in memory.md §2, may be aliased through &, may hold reference-type and & fields, and is moved rather than copied. Either kind may recurse, through a member the compiler boxes (see adt.md §4). Placement — stack or heap — is an unobservable implementation choice for both kinds (see memory.md §3.5).
package Graph;
type Node = #struct { // reference type: identity, may hold `&`, moved not copied
_id Int;
scale Float;
label String;
}
Story:
stories/types.md— “Two axes instead of a keyword per kind”. Story:stories/types.md— “What#actually changes, and the boxing trap”.
2.2 Value types are transitive and mutable in place
A value-type body contains only field declarations, stored inline apart from any member the compiler boxes (see memory.md §3.3). A value type MUST NOT contain a reference-type or & field, and this holds transitively: a value type reachable through a value type must itself be a value type (see memory.md §2.10). The restriction makes a value copyable and shareable-by-snapshot with no ownership bookkeeping. It does not stop a value type from containing itself (see adt.md §4).
A value is mutable in place: a mut method may write its fields, because the subject is a borrow of the caller’s storage rather than a copy (see effects.md §2.3 and functions.md §2.4). A value’s storage slot may also be overwritten wholesale.
package Math;
type Vec2 = struct { // value type: copied, transitively value, mutable in place
x Float;
y Float;
}
pos Vec2(1.0, 2.0);
pos!setX(Float(3.0)); // legal: mut method writes the field through a borrow of pos
pos = Vec2(3.0, 4.0); // legal: overwrites the whole value
2.3 Field visibility is name-based
A field whose name begins with _ is private to the package that declares its type. Any declaration in that package may name it — read it, write it, or assign it in init{ } — whether it is a method, function, operator, constructor, subscript, lambda, or constant. No declaration in another package may name it, including methods whose subject has that type (functions.md §6.3).
All fields whose names do not begin with _ are public.
A leading _ thus draws the same boundary on a field as on a package-scope declaration (packages.md §4.1): the package is the unit of privacy. A type and the declarations written alongside it in its package work on the same internals, so all of them reach its _ fields.
package Graph;
Int scaledId(this Node, factor Int) => this._id * factor; // a method in Graph
Bool ==(left Node, right Node) => left._id == right._id; // an operator in Graph
package render;
import Graph;
Int peek(this Graph$Node) => this._id; // ILLEGAL: _id is private to Graph
Story:
stories/lexical.md— “Privacy lives in the name”. Story:stories/lexical.md— “Field privacy moves to the package”.
2.4 Type bodies contain no behavior
Methods, constructors, overload rules, and function values live at package scope. A reader can inspect a type body to learn layout without scanning for behavior.
2.5 struct and variant share one body grammar
A struct is a product mould: a value of the type it declares has all of its members at once. A variant is a sum mould with the same body grammar: a value has exactly one of its members at a time. The body of a variant is byte-for-byte the same shape as a struct body; the keyword alone flips product into sum.
type Color = struct { r Int; g Int; b Int; } // value product type: has r and g and b
type Shape = variant { dot Dot; line Line; } // value sum type: has dot or line
The # modifier (§2.1) is the other axis: struct/#struct are the product pair, variant/#variant the sum pair. A value mould — struct or variant — declares a value type: transitively value, so it MUST NOT contain a reference-type field or an & field (§2.2, memory.md §2.10). A reference mould — #struct or #variant — declares a reference type, which may hold reference-type and & fields. Both may recurse, their recursive members boxed into the dynamic region (see adt.md §4). The body syntax is symmetric across these four combinations; the keyword picks product versus sum and the # picks value versus reference. Because # marks only a mould or a foreign handle, a reference type defined in Zane comes into being only through such a declaration and is always named there (§5.3). An intrinsic type is defined nowhere in Zane — the compiler supplies it — so it carries no #: @primitives$ListRef<T>, @runtime$Console, and @runtime$Runtime are reference types without one.
Story:
stories/types.md— “Confining#to the body forms”.
See also:
adt.mdfor the canonical rules onvariant,enum, pattern matching, and enum maps.adt.md§3 for the full struct-versus-variant symmetry.
2.6 The fundamental types and the core package
Int, Float, I32, F32, U8, Bool, String, Unit, Duration, Array<T, n>, ArrayRef<T, n>, List<T>, and ListRef<T> are the fundamental types: the types the core package declares and nearly every Zane program uses. The term fundamental describes their purpose, not a standing in the language. core is an ordinary package — a project fetches, versions, pins, and remaps it like any other dependency (dependencies.md §14) — and a program reaches its members through an import on the same terms as any other package’s (packages.md §3).
The language names none of them. The control-flow intrinsics take storage primitives, a subject of any type and a function value over it, or no arguments at all (control-flow.md §4.1), so no construct in the grammar depends on a declaration in any package.
core’s own declarations tie the fundamental types to ordinary source. The core package defines them over storage primitives in the @primitives$ namespace, and it declares the implicit constructors that carry a value into one: from the compiler concept types that represent source literals, so 20 becomes an Int, 2.5 a Float, and "a" a String at a coercion site, and from a fundamental type back to its own storage primitive — Bool to @primitives$Bool, which is what carries a condition into @controlflow$branch, and Int to @primitives$I64, which is what carries a count into @controlflow$repeat. core also declares String as a value type over @primitives$String, with an implicit constructor from @concepts$String, which builds through @primitives$String.escaped (§2.7), and one back to @primitives$String. Strings follow the ordinary deep-copy and borrowed-parameter rules (memory.md §2.3 and §2.9); they have no owning identity and cannot be targeted by an & reference. core’s Unit is declared over @primitives$Unit in the same way. Duration is a span of time, a whole number of nanoseconds held in an Int; Duration.nanoseconds, Duration.milliseconds, and Duration.seconds each build one from an Int, and it is what core‘s setInterval waits (control-flow.md §3.7). Explicit Bool(true) and Int(20) construction remains legal. A storage primitive has no operators, so core writes the fundamental types’ operators over the machine operations of @operators$ (operators.md §2.6). None of this is special-cased: the conversions are ordinary implicit constructors under §4, visible by the home-package rule of §4.5, and another package may declare the same kind of conversion for its own types.
Int accepts a literal only from @concepts$Int, so a float literal never becomes an Int: Int(2.5) is a type error, and so is a 2.5 at a coercion site that needs an Int. Float accepts a literal implicitly only from @concepts$Float, so a 2 at a coercion site that needs a Float is a type error. Float(2) is legal: core declares an explicit Float constructor that takes @concepts$Int and builds the Int first. The conversions a numeric type’s package declares determine which literals the type accepts, so a package declaring its own numeric type chooses which literals it accepts by declaring its own conversions (lexical.md §7).
Int and Float hold @primitives$I64 and @primitives$F64, and they are the types a literal becomes by default. I32 and F32 hold @primitives$I32 and @primitives$F32, for storing many values in half the space. They convert from the same literal concepts as Int and Float, and from each other only by constructor, under the rule for the scalar primitives (§2.9): Int(x) and Float(x) widen exactly, and the names I32.wrap, I32.truncate, and F32.round show how each conversion loses a value. A call whose arguments are all literals could then match both an Int and an I32 overload, and the compiler does not choose between them (generics.md §5.4). So wherever core and its math package declare a function for both widths, they also declare one taking the literal’s concept type, which builds the Int or Float: abs(3) is an Int, and sqrt(2.0) a Float.
Story:
stories/types.md— “coregainsI32andF32as storage types, andIntstays the default”.
U8 holds @primitives$U8, a byte from 0 to 255, so a List<U8> holds one byte per element. It is a storage type with no arithmetic: a program converts a byte with Int(b) to compute with it and stores an Int as a byte with U8.wrap(i), which keeps the integer’s low 8 bits. Int(b) and I32(b) are exact. U8 converts implicitly from @concepts$Int, so a literal from 0 to 255 is a byte at a coercion site, and it has == and <, each with an overload taking the literal’s concept on either side.
data List<U8> = List(U8);
data!push(U8.wrap(code)); // stores code's low 8 bits
next Int = Int(data[1]) + 1; // computes in Int
Story:
stories/types.md— “coregainsU8, a byte that is stored and never computed with”.
Because core is an ordinary dependency, two of its versions may be linked side by side like any other package’s (dependencies.md §11), and a project that wants them collapsed opts into remapping (§15 there). No version of Int is forced on a program, and none is the language’s.
A file that writes Int therefore imports core first, most often with the whole-package form import core$ (packages.md §3.3). Examples throughout this specification are written as though that import were already present, so core’s members appear unqualified in them.
Story:
stories/dependencies.md— “corebecomes an ordinary package over a primitive floor”.
Unit is the unit type. Its core declaration is an empty value struct, so it has exactly one logical value and zero-sized storage. Unit() is its ordinary core constructor. It may appear wherever any other value type may appear, including symbols, fields, arrays, generic arguments, function parameters, and return types.
type Player<T Type> = #struct {
name String;
extraSettings T;
}
Player<T>(name String, extraSettings ^T Type) => init{name; extraSettings;}
player Player<Unit> = Player("Manuel", Unit());
completed Unit = performWork();
An implementation may erase only the runtime storage of Unit values, including fields, array elements, and constructor results. It MUST still evaluate every expression that produces a Unit value at its original program point and in its original order. Storage erasure never removes side effects or otherwise changes observable evaluation.
Story:
stories/types.md— “Unitbecomes an ordinary type, andcoreleaves the package model”.
2.7 Literals and their storage primitives
A source literal is a value of a compiler concept type (syntax.md §2.8). The concept type is the literal’s own type, under the name Zane gives it. Six storage primitives take a literal directly: the integer scalars @primitives$I32 and @primitives$I64 and the byte primitive @primitives$U8, which take @concepts$Int; the float scalars @primitives$F32 and @primitives$F64, which take @concepts$Float; and @primitives$String, the string storage primitive described below. @primitives$Bool is a machine-word scalar as well.
Each of the six has a compiler-provided constructor from its literal’s concept type, and @primitives$String has a second, the named constructor escaped, described below, and one from each scalar primitive (§2.11). A scalar also converts from each other scalar, and @primitives$U8 from the integer scalars (§2.9). Packages may declare conversions to primitives under §4:
@primitives$U8(value @concepts$Int)
@primitives$I32(value @concepts$Int)
@primitives$I64(value @concepts$Int)
@primitives$F32(value @concepts$Float)
@primitives$F64(value @concepts$Float)
@primitives$String(value @concepts$String)
@primitives$String.escaped(text @concepts$String)
A concept is not storage, so the constructor that receives the concept determines which primitive it becomes: @primitives$I32(7) and @primitives$I64(7) are both legal.
These constructors are not implicit, so a literal never becomes a primitive by itself. A literal is accepted where the parameter’s type is the literal’s own concept type, or a type with an implicit constructor from that concept type (§4.2). Such a type calls the primitive’s constructor inside its own conversion:
type Count = struct { value @primitives$I64; }
implicit Count(literal @concepts$Int) => init{value = @primitives$I64(literal);}
A parameter of a primitive type therefore takes a primitive, or a type with an implicit constructor to it, and never a bare literal. Implicit constructors do not chain (§4.3), so a literal does not pass through such a type on its way to the primitive either:
@controlflow$repeat(@primitives$I64(3), { console!print("hi"); }); // legal: the primitive constructed explicitly
@controlflow$repeat(Int(3), { console!print("hi"); }); // legal: Int converts implicitly to @primitives$I64
@controlflow$repeat(3, { console!print("hi"); }); // ILLEGAL: no implicit constructor from @concepts$Int to @primitives$I64
The numeric arguments are values of leaf concept types, so they are known at compile time, and their constructors embed them in the primitives. A string concept may include runtime interpolation (§2.8); its constructor materializes the text when those values are available. A literal the primitive cannot represent is a compile-time error: an integer literal outside the range of the integer or byte primitive it builds, 0 to 255 for @primitives$U8, or a float literal whose magnitude exceeds the largest finite value of the float primitive it builds.
big @primitives$I32(9999999999); // ILLEGAL: out of range for @primitives$I32
@primitives$String is a string primitive: a value type whose fixed-size handle records the native address of its owned bytes in the dynamic region (memory.md §3.6), their length in bytes, and the backing block’s allocation metadata. The bytes carry no terminator. A consumer that needs a terminator adds one itself. A copy owns independent bytes; a method borrows the value under the ordinary rules. The primitive has no identity and cannot be targeted by an & reference.
The compiler-provided string constructor concatenates the string concept’s literal fragments and interpolated string values in their written order (§2.8). Every backslash sequence left in the fragments (lexical.md §7.1) stays in the string as written.
@primitives$String.escaped builds the same string with the text escapes in its literal fragments read:
| Text escape | Byte |
|---|---|
\n |
Line feed |
\t |
Horizontal tab |
\r |
Carriage return |
\0 |
Zero byte |
\\ |
One backslash |
Any other backslash sequence stays as written. escaped reads the fragments after the literal’s own structure has been read, so a backslash followed by an n reaches its result from the source \\\\n: the literal turns that into \\n, and escaped into a backslash and an n. An interpolated value is copied as it is; escaped reads only the fragments.
raw @primitives$String("a\nb"); // four bytes: a, backslash, n, b
@primitives$String.escaped("a\nb") // three bytes: a, line feed, b
@primitives$String.escaped("\%raw") // raw's four bytes, unread
A package constructor accepting the concept selects between the two, or interprets the literal fragments by its own rules, for example as regex syntax. Interpolated values remain distinct from those fragments and are not rescanned as source escapes or interpolation. @runtime$Console borrows the resulting primitive and writes its bytes as they are (effects.md §6.6).
a String("hello");
b String = a; // deep copy: a and b own independent bytes
b = String("goodbye"); // a still contains hello
bad &String = a; // ILLEGAL: String is a value type
type Label = struct { text String; } // legal: value-type field
Story:
stories/types.md— “Text without identity”.
Story:
stories/types.md— “@primitives$String.escapedreads text escapes when a consumer asks”.
Story:
stories/types.md— “How a literal lowers into primitive storage”.
2.8 String concepts and interpolation
A string literal, interpolated or not, carries @concepts$String. It is a concept rather than storage and follows the parameter-only rule of syntax.md §2.8. It contains an ordered sequence of literal text fragments and interpolated @primitives$String values. A literal without interpolation is known at compile time; an interpolated concept may contain runtime values. Its fragments and interpolation sites are fixed at compile time, but its completed text need not be.
At each \%var, the compiler resolves var as a value symbol in the caller’s scope. The site requires @primitives$String and is a coercion site (§4.2): a primitive string is accepted directly, or exactly one visible applicable implicit constructor converts the source to that primitive. The ordinary source restriction (§4.4), home-package rule (§4.5), ambiguity check, and no-chaining rule (§4.3) all apply. There is no automatic numeric formatting or special conversion from a reference type; a number becomes text through its conversion to @primitives$String (§2.11).
Each interpolation is evaluated once, in written order, when the containing literal is evaluated. The concept captures a copy of the resulting primitive string under memory.md §2.3, not a reference or a deferred lookup of the symbol. Later changes to the source do not change the captured value. Conversions follow the ordinary effect and abort-handling rules. The concept does not require an intermediate concatenated storage string; its consumer may build directly in its eventual destination.
name String("enrique");
console!print("hello \%name"); // String converts to @primitives$String; name stays usable
raw @primitives$String("enrique");
console!print("hello \%raw"); // primitive accepted directly
literal @concepts$String = "hello"; // ILLEGAL: concepts cannot be stored
The language recognizes quote escaping, backslash escaping, and interpolation as literal structure (lexical.md §7.1). Other backslash sequences remain text for the consumer to interpret. Consumer interpretation does not change the caller’s scope or give the consumer access to variables named in the text.
Story:
stories/lexical.md— “Literal structure and consumer interpretation”.
2.9 Conversions between scalar primitives
Each scalar primitive converts to each other one through a constructor of the target. None of them is implicit, so a conversion is always written where it happens.
A conversion that is exact for every value of its source is the target’s anonymous constructor:
@primitives$I64(value @primitives$I32)
@primitives$F64(value @primitives$F32)
@primitives$F64(value @primitives$I32)
Every other conversion can lose a value, and is a named constructor (§3.4), named for the way it loses a value:
| Constructor | Source | Result |
|---|---|---|
@primitives$I32.wrap |
@primitives$I64 |
The source’s low 32 bits, read as a signed integer |
@primitives$I32.truncate, @primitives$I64.truncate |
@primitives$F32, @primitives$F64 |
The source rounded toward zero, held to the target’s range |
@primitives$F32.round |
@primitives$I32, @primitives$I64, @primitives$F64 |
The @primitives$F32 nearest the source |
@primitives$F64.round |
@primitives$I64 |
The @primitives$F64 nearest the source |
round rounds once, from the source straight to the target, and a source exactly halfway between two values the target holds rounds to the value whose lowest significand bit is zero, IEEE 754’s round half to even. @primitives$F32.round of an @primitives$F64 is IEEE 754’s conversion between the two formats: a NaN gives a NaN, an infinity the infinity of its sign, and a finite source too large for rounding to nearest to give a finite @primitives$F32 the infinity of its sign as well. When the source rounded toward zero lies outside the target’s range, an infinity included, truncate gives the target’s least or greatest value, whichever is nearer, and a NaN truncates to zero, so every conversion has a result.
wide @primitives$I64 = @primitives$I64(small); // exact: small is an I32
whole @primitives$I32 = @primitives$I32.truncate(ratio); // drops ratio's fraction
near @primitives$F64 = @primitives$F64.round(count); // count is an I64 and may be rounded
The byte primitive @primitives$U8 converts to and from the integer scalars by the same rule. Every byte is an integer from 0 to 255, so @primitives$I32(value @primitives$U8) and @primitives$I64(value @primitives$U8) are exact. The named constructor @primitives$U8.wrap takes an @primitives$I32 or an @primitives$I64 and keeps its low 8 bits, read as an unsigned integer, so -1 wraps to 255. A byte converts to a float only through an integer scalar.
Story:
stories/types.md— “The scalar primitives becomeI32,I64,F32andF64, converted by constructor”.
2.10 Reading a number from a string primitive
Two methods of the string primitive read the number its text spells:
@primitives$I64?@primitives$Unit parseI64(this @primitives$String)
@primitives$F64?@primitives$Unit parseF64(this @primitives$String)
parseI64 accepts the text of an integer literal written without digit separators (lexical.md §7), optionally preceded by -. parseF64 accepts the text of an integer or a float literal written without digit separators, optionally preceded by -. Nothing else is accepted: no whitespace, no +, and no other characters. Each gives the value the text spells. parseF64 gives the @primitives$F64 nearest to it, rounding half to even as round does (§2.9).
A call aborts with @primitives$Unit when the text is not in its accepted form, and when its value does not fit: for parseI64, a value outside the range of @primitives$I64, and for parseF64, one too large in magnitude to round to a finite @primitives$F64.
Reading can fail, so neither method is a constructor. A constructor cannot abort.
count @primitives$I64 = text:parseI64() ?? @primitives$I64(1000);
A third method reads a number from part of a string, without copying that part into a string of its own:
@primitives$F64?@primitives$Unit parseF64At(this @primitives$String, start @primitives$I64, count @primitives$I64)
parseF64At reads the count bytes from byte start, counted from 1 as byteAt counts them (§2.12), exactly as parseF64 reads a whole string. A range outside the string stops the program (control-flow.md §5.2).
Story:
stories/types.md— “Reading a number from text is a method, because it can fail”.
2.11 Writing a scalar primitive as text
The string primitive has one constructor from each scalar primitive, which writes the number as text:
@primitives$String(value @primitives$I32)
@primitives$String(value @primitives$I64)
@primitives$String(value @primitives$F32)
@primitives$String(value @primitives$F64)
A number becomes text only where a program calls one of these, directly or inside a package’s own conversion. Interpolation does no formatting of its own (§2.8).
An integer’s text is its decimal digits, with no leading zeros, preceded by - when it is negative: 0, 42, -42.
A float’s text is nan for a NaN, and inf or -inf for an infinity. The constructor writes any other float as the shortest decimal that spells it. The constructor selects the text from candidates, which it makes for each digit count k from 1 to 17 for an @primitives$F64, and from 1 to 9 for an @primitives$F32:
- It rounds the value to the nearest number of
ksignificant decimal digits and drops the digits after the last nonzero one. - It writes the digits in scientific notation: the first digit, then
.and the remaining digits when any remain, theneand the decimal exponent. A-precedes a negative exponent, and the exponent has no+and no leading zeros, as in2.5e-7and1e22. - When the exponent is at least
-4and less thank, it also writes the digits in fixed notation: the digits with a.placed by the exponent, and0.before them when the exponent is negative. It writes the zeros needed to reach the.and omits the.when no digit follows it, so the candidates include0.001,100, and2.5. - A negative value’s candidates begin with
-, a negative zero’s included.
The constructor keeps a candidate when it spells the value: the number it writes, rounded to the float’s own width as round rounds (§2.9), is the value itself, a zero’s sign included. A candidate of 17 digits, or 9 for an @primitives$F32, always spells the value, so at least one is kept. The text is the shortest candidate kept. A tie in length goes to the candidate with fewer digits, not counting the zeros before its first nonzero digit, and a remaining tie goes to fixed notation.
@primitives$String(@primitives$F64(1.0)) // "1"
@primitives$String(@primitives$F64(100.0)) // "1e2": as short as "100", with fewer digits
@primitives$String(@primitives$F64(0.001)) // "1e-3": shorter than "0.001"
@primitives$String(@primitives$F64(0.25)) // "0.25"
@primitives$String(@primitives$F32(0.1)) // "0.1": the F32 nearest 0.1, though its exact value is not 0.1
Scientific notation is not part of a float literal (lexical.md §7), so parseF64 (§2.10) does not read a text in that notation back.
Story:
stories/types.md— “The string primitive’s bytes and numbers are specified, and a byte set becomes its own primitive”.
2.12 A string primitive’s bytes and byte sets
A string primitive is a sequence of bytes, and three methods read them:
@primitives$I64 byteCount(this @primitives$String)
@primitives$U8 byteAt(this @primitives$String, index @primitives$I64)
@primitives$I64 hashBytes(this @primitives$String)
byteCount gives the string’s length in bytes. byteAt gives the byte at the position index, counted from 1 (control-flow.md §5.1). A position outside the string stops the program (control-flow.md §5.2). hashBytes gives a hash of the string’s bytes: two strings with the same bytes have the same hash within one run of a program, and the value is not otherwise specified.
word @primitives$String("byte");
length @primitives$I64 = word:byteCount(); // 4
first @primitives$U8 = word:byteAt(@primitives$I64(1)); // 98, the byte of b
A byte set is a set of the 256 byte values, and the value type @primitives$ByteSet holds one. A copy of one is a set of its own. Its layout is the compiler’s, and the only way to build one is the method byteSet:
@primitives$ByteSet byteSet(this @primitives$ArrayRef<T Type, 256>)
byteSet gives the set of the bytes whose flags are set: the flag of the byte b is at position b + 1. T is @primitives$Bool, whose flag is set when it is true, @primitives$U8, whose flag is set when it is not 0, or a struct whose only field is one of those types or another such struct, as core’s Bool and U8 are. A byteSet call with any other T is a compile-time error.
Two methods search a string for the bytes in a set:
@primitives$I64 findAny(this @primitives$String, from @primitives$I64, count @primitives$I64, set @primitives$ByteSet)
@primitives$I64 findPair(this @primitives$String, from @primitives$I64, count @primitives$I64, first @primitives$ByteSet, gap @primitives$I64, second @primitives$ByteSet)
findAny gives the first of the count positions from from whose byte is in set, or 0 when none is. findPair gives the first of those positions whose byte is in first and whose byte gap positions later is in second, or 0 when none is. Each search reads the bytes it tests, so a call whose count is below 1 reads none and gives 0. Otherwise findAny’s count positions from from lie in the string, findPair’s gap is at least 0, and its count + gap positions from from lie in it; any other call stops the program (control-flow.md §5.2).
vowels @primitives$ByteSet = flags:byteSet(); // flags marks a, e, i, o and u
at @primitives$I64 = word:findAny(@primitives$I64(1), word:byteCount(), vowels); // 4, the e
Story:
stories/types.md— “The string primitive’s bytes and numbers are specified, and a byte set becomes its own primitive”.
3. Constructors and Initialization
3.1 Constructors are package-scope declarations
A constructor is a package-scope verb named after the type. It has no this parameter because no object exists yet.
Constructors use the same block-bodied or expression-bodied surface forms as other package-scope verbs, except that the written type name is the return type. The body produces a value of that type, and the type’s mould determines how:
- a
structor#structconstructor builds the result withinit{ ... }, which assigns every field (§3.7); - an
enumor#enumconstructor returns one of the enum’s members (adt.md§2.2); - a
variantor#variantconstructor returns a case, which its body builds by naming the case (adt.md§3.3).
type Colors = enum [ red, green, blue ];
type Countdown = variant { done Unit; more Countdown; }
Colors() => Colors.red;
Countdown() => Countdown.done(Unit());
Because every mould may declare constructors, a generic body may construct a value of a type parameter (T()) whatever mould the type argument has, as long as the argument’s type declares a matching constructor (generics.md §5).
Story:
stories/types.md— “Naming a type by its meaning, not by its construction”. Story:stories/types.md— “Every mould gets constructors”.
3.2 Positional constructors
Positional constructors declare ordinary parameters. A struct or #struct positional constructor returns init{ ... }; an enum or variant one returns a member or a case (§3.1).
package Graph;
Node(id Int, scale Float, label String) {
return init{
_id = id;
scale = scale;
label = label;
}
}
Expression-bodied constructors are equivalent. As for any verb, => expr is pure shorthand for { return expr }, so the form below is exactly { return init{x; y;} }:
package Math;
Vec2(x Float, y Float) => init{x; y;}
Positional constructors MAY be overloaded by arity or parameter types.
Constructor parameters do not need to repeat private-field underscores. It is normal to map a public-facing parameter such as id into a private field such as _id explicitly inside init{ }.
A constructor body is an ordinary verb body: a sequence of statements that ends by returning a value of the constructor’s type, which for a struct is an init{ }. It may run any computation before that return, exactly like a function. A constructor is nothing more than a verb that is named after its type and returns a value of that type — it is indistinguishable from a builder helper that ends in a constructor call, apart from its name.
package Graph;
Node(id Int, scale Float, label String) {
scaled Float = scale * scale; // ordinary statements run first
nextId Int = id + Int(1);
return init{
_id = nextId;
scale = scaled;
label = label;
}
}
3.3 Field constructors
A constructor may also declare fields directly in its parameter header:
package Math;
type Vector = struct {
x Int;
y Int;
}
Vector{x Int; y Int;} {
return init{x; y;}
}
This form is the canonical constructor syntax when the constructor parameters map directly to fields. Only a type with fields — a struct or #struct — declares a field constructor; an enum or variant constructor is positional (§3.2). A field-constructor entry of a reference type is a parameter like any other (memory.md §2.9): an entry that fills an owning field is written ^T and takes the owner, and one that fills an & field is written &T.
Field-constructor entries may also declare default values. They use the same initialized declaration forms as ordinary storage declarations. A call may omit any field whose constructor entry provides one:
type Weapon = #struct {
name String;
fireRate Float;
damage Float;
}
Weapon{
name String("Pistol");
fireRate Float(1.0);
damage Float(10.0);
} {
return init{name; fireRate; damage;}
}
starter Weapon{fireRate = Float(2.0);}
3.4 Named constructors
The by-type-name constructor (§3.2, §3.3) is the anonymous constructor. A type may also declare named constructors, each a verb whose name is the type followed by a .name suffix, giving one type several construction paths that a bare Type(...) cannot distinguish.
package Math;
type Vector2 = struct { x Float; y Float; }
Vector2.zeros() => init{ x = Float(0.0); y = Float(0.0); }
Vector2.diagonal(n Float) => init{ x = n; y = n; }
o Vector2.zeros(); // o : Vector2
d Vector2.diagonal(Float(3.0)); // d : Vector2
A named constructor is an ordinary constructor in every other respect. Naming a verb after a type — with or without the .name suffix — is the capability marker that makes it a constructor (see functions.md §8.2): the return type is implicit (the type named, Vector2) and, for a type with fields, init{ } is unlocked. The suffix only distinguishes the named constructor from the other constructors of the type; it does not change the type the constructor returns. So a named constructor:
- declares positional parameters or, on a
structor#struct, the field-header form (§3.2, §3.3) like any constructor; - overloads by parameter types, alongside the anonymous constructor and the other named constructors;
- is called by its qualified name and yields the base type —
Vector2.zeros()is aVector2, never aVector2.zerostype.
The casing rule (see lexical.md §3) keeps the call unambiguous: Vector2.zeros() has an uppercase subject, so .zeros is a member of the type — a constructor — while v.zeros has a lowercase subject, so .zeros is a field or method of a value. The two never collide.
A named constructor MUST NOT be marked implicit: an implicit constructor is an anonymous single-argument conversion the compiler inserts at a coercion site (§4), and a named constructor is only ever called by its written name, so the compiler has nothing to insert.
Every mould may declare named constructors, as it may declare anonymous ones (§3.1). A storage primitive’s named constructors are the compiler’s own, such as the lossy conversions of §2.9.
type Colors = enum [ red, green, blue ];
Colors.background() => Colors.blue;
shade Colors.background(); // shade : Colors, holding the member blue
A named constructor shares the Type.member surface with an enum member (Colors.red, adt.md §2) and with a variant case (Expr.intLit("5"), adt.md §3.2). A named constructor’s name MUST therefore differ from every member and every case of its type, so that Type.member names exactly one of them: Colors.background is legal beside the member Colors.red, and a constructor named Colors.red is an error. Naming a member or a case stays built-in syntax with no verb behind it; a named constructor is a declared verb that shares its spelling.
Story:
stories/types.md— “Named constructors, and the syntax variants already had”. Story:stories/types.md— “Every mould gets constructors”.
3.5 Implicit field access in constructor calls
Field-constructor call sites may use implicit field access when the argument expression name matches the field name:
x Int(3);
y Int(2);
vec Vector{x; y;}
Vector{x; y;} is shorthand for Vector{x = x; y = y;}.
3.6 Implicit field access in init{ }
Inside init{ }, a bare field name is shorthand for fieldName = fieldName when a symbol of that name is in scope:
Vector{x Int; y Int;} {
return init{x; y;}
}
This is shorthand for:
Vector{x Int; y Int;} {
return init{
x = x;
y = y;
}
}
3.7 init{ } is a constructor-only expression
init{ } is valid only inside the body of a constructor for a type with fields — a struct or #struct — but within that body it is an ordinary expression of the enclosing constructor’s type. An enum or variant constructor has no fields to assign and returns a member or a case instead (§3.1). The constructor may return it directly or assign it to a local before returning it.
Vector{x Int; y Int;} {
temp Vector = init{
x = x;
y = y;
}
return temp;
}
Every field of the target type MUST be assigned exactly once, either explicitly or through implicit field access shorthand. The entries run in the order written, so an entry that moves a parameter spends it for every entry after it (lifetimes.md §1.6).
Story:
stories/lifetimes.md— “Running the examples”.
3.8 Constructors do not use mut
Constructors are not methods. They create new values rather than mutating an existing subject, so mut does not apply.
3.9 & fields require & constructor parameters
An & field is legal only in a reference type (#struct/#variant), since a value type is transitively value (§2.2). A constructor that assigns a value to an & field must declare the corresponding parameter as &T. A borrow T is never stored, and a taken ^T is roaming, which nothing references (memory.md §2.9). The caller must then supply a reference under memory.md §2.8: either an existing &T value or a settled place that may mint one. A bare settled symbol, or a path from a settled root through struct fields and ArrayRef elements, may mint a reference; a roaming owner, a ListRef element, a variant payload, and any temporary may not. A read whose value is already &T, such as weapons[1] for ArrayRef<&Weapon, 2> or racks[1].weapon for a list of objects with an &Weapon field, remains legal because it copies the stored reference rather than minting one from the element slot.
package Vehicle;
type Car = #struct {
engine &Engine;
}
// legal: `&` parameter allows storing into `&` field
Car(engine &Engine) {
return init{engine = engine;}
}
// ILLEGAL: a borrow cannot be bound into `&` storage
Car(engine Engine) {
return init{engine = engine;} // ERROR: a borrow is never stored
}
Call sites:
garage Garage();
car Car(garage.spare); // legal: a field access is a reference source
engine Engine();
car Car(engine); // legal: a bare settled symbol is a reference source
car Car(Engine()); // ILLEGAL: a temporary cannot initialize an `&` field
What still constrains such a field is lifetime, not source: the object it points at must have an owner whose scope outlives the scope of the place holding the & (lifetimes.md §1.1). A field takes its root symbol’s scope, so that comparison does not stop at construction — every later store of the containing value repeats it, over the references that value carries (lifetimes.md §1.10). A constructor cannot make the comparison itself, because init{ } has no scope until the caller says where the object goes; it records which parameters land in & fields and each call settles the comparison (lifetimes.md §1.11). Recursion is not one of these cases at all: a recursive member is an ordinary owning field the compiler boxes, so it needs no & and no reference source (see adt.md §4).
Story:
stories/memory.md— “Bare symbols become guest sources again”.
A reference type whose fields are all plain owners takes them as ^T parameters, moving each into the object it builds:
type Car = #struct {
engine Engine;
}
Car(engine ^Engine) {
return init{engine = engine;}
}
car Car(Engine()); // legal: a temporary moves into the field
3.10 Type and number parameters
A constructor for a parameterized type receives its type and number parameters in one of two ways, because a constructor call never carries a <> type-argument list. A constructor has no <> header: a parameter introduced inline — on a value parameter’s type or in a nested type — is inferred from the value arguments; a parameter declared as a Type or @concepts$Int value parameter is passed explicitly as an ordinary argument.
// inferred: T is introduced inline and deduced from the value arguments
Vector<T>(x T Type, y T Type) {
return init{x; y;}
}
// explicit: the type and size are passed as arguments
Array<T, n>(T Type, n @concepts$Int) {
// zero-initialise n elements of type T
}
The constructor’s name is its return type, so a constructor for a parameterized type names the applied type (Vector<T>, Array<T, n>); the <...> holds bare references to the inline-introduced or explicitly passed parameters (it carries T, not T Type, so it is not a reintroduced header). The call is always by bare name.
A Type value parameter is usable as a type inside the body (for example, T(0)); an @concepts$Int value parameter is usable as a number. A constructor is always called by its bare name: Vector(Int(2), Int(3)) infers T, while Array(Int, 10000) passes the type and size explicitly.
See also:
generics.md§5 for the complete rules on how types and numbers reach a constructor, and §3 for the unified parameter system.
4. Implicit Constructors
4.1 The implicit modifier
A constructor marked with the implicit modifier declares a single-parameter conversion. Implicit constructors MUST declare exactly one parameter and MUST NOT use field-constructor form.
package Units;
type Meters = struct {
value Float;
}
type Feet = struct {
value Float;
}
// implicit conversion from Feet to Meters
implicit Meters(feet Feet) => init{value = feet.value * Float(0.3048);}
Unit printDistance(d Meters) {
...
return Unit();
}
At a coercion site — a position whose destination type is fixed by a callable or language construct (see §4.2) — if the source expression has a different type and exactly one applicable implicit constructor exists, the compiler inserts that constructor call automatically.
printDistance(Feet(Float(10.0))); // coercion site: parameter expects Meters, Feet provided
// desugars to: printDistance(Meters(Feet(Float(10.0))))
An implicit constructor is also an ordinary constructor, which a call may name to convert explicitly. A call that names it finds it where a coercion site does, in the home package of either of its types (§4.5), so Meters(feet) reaches a conversion Feet’s package declares, and @primitives$String(text) reaches the one core declares from its String.
A named field entry of a field-constructor call is a coercion site too, so the conversion fires inside the braces:
type Trip = struct { distance Meters; label String; }
Trip{distance Meters; label String;} => init{distance; label;}
Trip{distance = Feet(Float(10.0)); label = "hike";} // field entry expects Meters, Feet provided
// desugars to: Trip{distance = Meters(Feet(Float(10.0))); label = "hike";}
The init{ } inside a constructor body is not a coercion site: there the constructor writes its own value’s fields, so like a return the conversion is written explicitly (see §4.2).
A declaration is not a coercion site, so the conversion must be written explicitly there:
distance Meters = Feet(Float(10.0)); // ILLEGAL: a declaration is not a coercion site
distance Meters = Meters(Feet(Float(10.0))); // legal: explicit conversion
4.2 Coercion sites
A coercion site is a position that passes a value into a contract whose destination type is fixed by a callable or language construct. These are the only positions where the compiler inserts an implicit constructor:
- Positional arguments of a function call, including a call to an intrinsic
- Positional arguments of a method call (the subject is excluded; see §4.6)
- Positional arguments of a positional constructor call
Type(...) - Positional arguments of a named-constructor call
Type.name(...) - Named field entries of a field-constructor call
Type{ field = expr; } - Entries of an enum-map declaration (
adt.md§6) - String interpolation sites
\%var, whose destination is@primitives$String(§2.8)
Anonymous and named positional constructors use their declared parameter types identically, so Type(...) and Type.name(...) arguments receive the same implicit conversions. A field-constructor call entry fills the constructor’s declared slot in the same way, and an enum-map entry fills the slot its declaration’s header declares. Control flow needs no entry of its own: branching and repetition are ordinary calls (control-flow.md §3) and a program calls the intrinsics beneath them like functions or methods, so the argument entries above already cover their conditions, bounds, and event sources.
An implicit constructor is never inserted at any other position. In particular, the following are not coercion sites:
- Symbol declarations with a type annotation:
name VarType = expr - Assignments to already-declared symbols:
name = expr - Field or subscript assignments:
obj.field = expr,arr[i] = expr returnexpressions, even when the return type is declared- Named field entries of an
init{ field = expr; }initializer inside a constructor body - Operands of an operator
At each of these positions but the last, the destination type is one you fix yourself — a local declaration, existing storage, the return type in the enclosing signature, or the fields the constructor builds through init{ } — rather than a contract supplied by a callee or language construct, so the conversion must be written explicitly. An operator’s operands are passed as written, and an operator accepts a literal through an overload that declares its concept type (operators.md §2.7).
At one coercion site requiring destination type T, given an argument with static type U, the compiler resolves the site locally:
- If
Uis exactlyT, accept the argument with no insertion. - Otherwise, collect all visible applicable
implicitconstructors fromUtoT. - If exactly one applicable implicit constructor exists, rewrite the argument as
T(arg). - If multiple applicable implicit constructors exist, the site is an ambiguity error.
- If none exist, the site is a normal type error.
Candidate collection follows the home-package rule of §4.5 and needs no import: an implicit constructor is declared in the home package of one of its endpoints, and that declaration makes it visible at a site whose destination is that type. core’s conversions from the compiler concept types are found this way like any other package’s, so literal coercion is the same algorithm rather than a separate compiler-only lowering rule.
4.3 No chaining
Implicit conversions are never chained. If no single-step implicit constructor exists from source type U to destination type T, the compiler does not search for a path U → V → T. The call is a type error.
4.4 Source and destination type constraints
The source type (parameter type) of an implicit constructor MUST be a value type or a compiler concept type in the @concepts$ namespace. It MUST NOT be a reference type or an &.
The destination type (return type, i.e., the type name of the constructor) MAY be a value type, a reference type, or a storage primitive in the @primitives$ namespace.
A primitive destination is what lets an intrinsic state its contract without naming any package’s type. @controlflow$branch takes a @primitives$Bool (control-flow.md §4.1), and core supplies the conversion from its own Bool; any other type may supply one too, subject to the orphan rule of §4.5, which a conversion declared in the type’s own home package satisfies.
type Celsius = struct { value Float; }
type Fahrenheit = struct { value Float; }
implicit Celsius(f Fahrenheit) => init{value = (f.value - Float(32.0)) * Float(5.0) / Float(9.0);} // legal: value → value
type Logger = #struct { verbosity Int; }
type LogConfig = struct { verbosity Int; }
implicit Logger(cfg LogConfig) { // legal: value → reference
return init{verbosity = cfg.verbosity;}
}
type Source = #struct { data String; }
type Destination = #struct { payload String; }
implicit Destination(s Source) { // ILLEGAL: source type is a reference type
return init{payload = s.data;}
}
4.5 Coherence and the orphan rule
An implicit constructor from type U to type T MUST be declared in the home package of either type. A third-party package MUST NOT declare an implicit constructor between two imported types. core is the home package of the fundamental types, and a package may no more add declarations to it than to any other package it does not own; a fundamental endpoint therefore does not by itself grant permission to declare a conversion.
This rule prevents conflicts when multiple packages independently define the same implicit conversion and ensures that the owner of at least one type controls the conversion behavior.
package Units;
type Meters = struct { value Float; }
// legal: declared in home package of Meters
implicit Meters(feet Feet) => init{value = feet.value * Float(0.3048);}
package Conversions;
import Units;
// ILLEGAL: neither Meters nor Feet is defined in Conversions
implicit Units$Meters(feet Units$Feet) => init{value = feet.value * Float(0.3048);}
4.6 Method subjects are never implicitly converted
The subject expression (this) in a method call is never subject to implicit conversion. This remains true even though method calls desugar to ordinary function calls. If the subject type does not match, the call is a type error.
Unit logDistance(this Meters) {
...
return Unit();
}
feet Feet(Float(10.0));
feet:logDistance(); // ILLEGAL: subject type is Feet, not Meters
See also:
functions.md§5 for how implicit constructors interact with overload resolution. Story:stories/types.md— “No exception for the bare literal”. Story:stories/types.md— “Coercion follows the call, not the store”.
5. Type Definitions and Aliases
Zane names types with two declaration keywords. type introduces a new distinct type; alias introduces an interchangeable name. Both use = as the delimiter, so the keyword alone carries the distinction.
5.1 type declares a distinct type
A type declaration introduces a new, distinct named type. The new type is structurally equal to its right-hand side but is not interchangeable with it.
type VectorInt = Vector<Int>; // distinct type; NOT interchangeable with Vector<Int>
A value of VectorInt and a value of Vector<Int> do not substitute for each other implicitly, even though their layouts match.
5.2 alias declares an interchangeable name
An alias declaration introduces a true alias: the new name and its right-hand side are fully interchangeable everywhere.
alias VectorInt = Vector<Int>; // fully interchangeable with Vector<Int>
5.3 The right-hand side is a type expression
The right-hand side of a type or alias declaration is any type expression: an applied generic (Vector<Int>), an Array<Int, 10000>, or an inline mould — struct { ... }, variant { ... }, or enum [ ... ] — in either its value form or its # reference form.
type Wrapper = struct {
vec Vector<Int>;
arr Array<Int, 10000>;
}
A named type is therefore always declared this way: type Name = struct { ... } or type Name = #struct { ... } (and likewise variant/#variant/enum). There is no standalone struct Name { ... } declaration form — a mould is a type expression that only names a type through a type (or alias) declaration.
A foreign handle, #handle{ ... }, is the one other right-hand side that declares a new type. It is no mould: it has no body and no value form, and it appears only after type (ffi.md §4.1).
These three forms — struct, variant, and enum — are the moulds: the constructs that give a type its shape. Each has a value form and a # reference form (§2.1), and a mould MUST appear only as the right-hand side of a type or alias declaration. Every other type position — a field, a parameter, a return type — names a declared type or an instantiation of one (Weapon, Vector<Int>, Array<Int, 10000>, &Node). Every type therefore has a type name, and a program calls the type’s constructors by that name (§3.1). The fundamental types follow the same declaration model inside core; see §2.6.
Story:
stories/types.md— “Every type is named, because construction calls it by name”. Story:stories/types.md— “Naming the moulds, and marking every one”.
5.4 The keyword carries the distinction
Intent lives entirely in the keyword — type versus alias — not in the punctuation. The = delimiter is identical in both forms, which keeps them visually parallel while making the distinct-vs-interchangeable choice explicit.
See also:
generics.md§4 for type expressions andsyntax.md§1 for the declaration grammar.
6. Summary
| Concept | Rule |
|---|---|
| Type body | Fields only — no methods or constructors inside the body |
| Value/reference axis | A type is a value type unless marked #; # marks only a mould — #struct/#variant/#enum — or a foreign handle, #handle (declared and named), each a distinct reference type with identity and &-aliasing, moved rather than copied; the unmarked moulds declare value types, and either kind may recurse |
| Mould | One of the three type-shaping forms — struct, variant, or enum; each has a value form and a # reference form; appears only as a type/alias right-hand side, so every constructible type is named |
| Use-site types | A field, parameter, or return type names a declared type or an instantiation (Weapon, Vector<Int>, &Node); a mould appears only as a type/alias right-hand side |
| Value type | Copied on assignment; transitively value (no reference-type or & field, anywhere downstream); mutable in place through a borrowed mut subject; storage may also be overwritten wholesale |
Reference type (#) |
Single ownership and stable identity; may hold reference-type and & fields; moved rather than copied; placement is unobservable |
| Fundamental type | Int, Float, I32, F32, U8, Bool, String, Unit, Duration, Array<T, n>, ArrayRef<T, n>, List<T>, or ListRef<T>; core declares them, and it is an ordinary package with no standing in the language |
| Literal storage primitive | @primitives$U8, @primitives$I32, @primitives$I64, @primitives$F32, @primitives$F64, or @primitives$String; each has a compiler-provided constructor, not implicit, taking its literal’s concept type, and @primitives$String also has escaped; packages may declare implicit conversions to primitives under §4; a literal the primitive cannot represent is a compile-time error |
| Scalar conversion | Each scalar primitive converts to each other through a constructor of the target, never implicit; an exact one is the anonymous constructor, and a lossy one is named for its loss: wrap, truncate, or round; @primitives$U8 converts to the integer scalars exactly and from them by wrap |
| String primitive | @primitives$String: a value type with owned bytes in the dynamic region and a fixed-size handle; no terminator or stored reference; copies are deep |
| Reading a number | parseI64 and parseF64 on @primitives$String read a literal’s text with an optional -, and parseF64At reads part of a string the same way; each aborts with @primitives$Unit on any other text or a value that does not fit; they are methods, since a constructor cannot abort |
| Writing a number | @primitives$String has a constructor from each scalar primitive: an integer’s decimal digits, and a float’s shortest decimal that spells it, in fixed or scientific notation, or nan, inf, or -inf |
| String bytes | byteCount gives a string’s length in bytes, byteAt the byte at a position counted from 1, and hashBytes a hash that is equal for equal strings within one run |
| Byte set | @primitives$ByteSet, a value type built only by byteSet from an @primitives$ArrayRef of 256 flags; findAny and findPair search a string’s bytes for the bytes in a set and give the first position found, or 0 |
| Text escapes | @primitives$String keeps a literal’s backslash sequences as written; @primitives$String.escaped reads \n, \t, \r, \0, and \\ in the literal’s fragments, never in an interpolated value |
| String interpolation | \%var captures a copied @primitives$String, accepting a direct primitive or one ordinary implicit conversion; the result remains a string concept and may carry runtime values |
Unit |
Empty core value type; Unit() constructs its sole value, which may be stored or used as a generic argument |
| Field visibility | Names starting with _ are private to the package that declares the type; all other names are public |
| Constructor | Package-scope verb named after the type, declarable on every mould; the written type name is the return type; no this; a struct constructor returns an init{...}, an enum constructor a member, a variant constructor a case |
| Named constructor | Type.name(...); yields the base type; never implicit; its name differs from every member and case of its type |
| Field constructor | Declared only on a struct or #struct; declares field parameters directly, may assign default values, and may use init{field;} shorthand |
| Implicit constructor | Single-parameter constructor marked implicit; inserted at callable arguments, named field-constructor entries, enum-map entries, and string interpolation sites — never at declarations, assignments, stores, return, the init{field = value;} inside a constructor body, or operator operands; no field-constructor form; source type must be a value type or compiler concept; destination may be a value type, a reference type, or a storage primitive; orphan rule applies |
& constructor parameter |
Caller must supply an allowed & source; callee may store into & fields |
^T constructor parameter |
Takes a roaming owner or a temporary; callee moves it into an owning field |
Plain T constructor parameter |
A borrow: read only, never stored; a value-type parameter is always one |
Type / @concepts$Int constructor parameter |
Accepts a type or a compile-time integer; inferred from inline introduction or passed explicitly as a value parameter |
type declaration |
Introduces a new distinct type, structurally equal to its right-hand side but not interchangeable with it |
alias declaration |
Introduces an interchangeable alternate name for a type expression |