Stories: Types
See also:
spec/types.md— the rules these chapters explain.
Two axes instead of a keyword per kind
A type in Zane answers two independent questions. The first is shape: is this a product (fields side by side) or a sum (one of several cases)? The second is kind: is this a value — copied, identity-less, transitively value — or a reference — a single-owner object with stable identity that other objects can point at? Those are orthogonal. A product can be either kind; so can a sum. Four cells in a two-by-two grid, and the design turns on refusing to fuse the two questions that make them.
The mainstream move is to spend a keyword on each cell, or on most of them: struct for the value product, class for the reference product, enum or union for sums, each a separate declaration form with its own rules bolted on. We rejected that, because it makes a reader learn four constructs where there are really two, and it hides the fact that value-versus-reference is the same distinction whether you are looking at a product or a sum. If class is “the reference one” for products, nothing in class shows you the sum counterpart of “the reference one” — the knowledge doesn’t transfer, because the grammar split it across unrelated keywords.
So we kept the two axes literally two axes. One keyword picks the shape — struct for a product, variant for a sum — and one modifier, #, picks the kind of type: unmarked is a value type, #-marked is a reference type. struct/#struct are the product pair, variant/#variant the sum pair, and the # carries the same meaning in both places (types.md §2.1). Learn # once and it composes across the whole grid. The value type is transitively value and mutable in place; the reference type carries identity and may hold & fields and recurse (types.md §2.2) — but that behavioural split rides on the one modifier rather than on a proliferation of keywords.
The cost is subtle and it takes the rest of this file to pay off. Writing the kind of type as a modifier invites reading it as an annotation — a mark you can staple onto any type expression the way you’d staple const or mut. #struct { … } reads as “the struct, but reference”; and if that is how # works, then #Int reads as “the Int, but reference”, and #T as “the T, but reference”, for any T at all. The first draft of the spec took exactly that reading and let # compose with every type expression, primitives included. Undoing that over-generous reading is the through-line of the last two chapters.
What # actually changes, and the boxing trap
Before deciding where # may appear, we had to be honest about its effect, because the intuitive answer is wrong and the wrong answer quietly justifies the over-generous grammar. Ask for the difference between Int and #Int and the reflex is: #Int is boxed — a heap allocation, a pointer to an Int instead of an Int. It looks boxed, because you can hold an &#Int and hand it around, and an object you point at surely lives behind a pointer.
That reflex is false, and the spec goes out of its way to make it false. Placement — stack or heap — is an unobservable implementation choice; a reference-type instance is put on the heap only when its size is dynamic or it is moved into a heap owner, and moving it into a longer-lived stack slot is just a relocation (memory.md §3.5). So “# means boxed” cannot be the distinction: two programs that differ only in where the compiler placed a #Int are the same program. What # actually adds is identity — an anchor (memory.md §4.1), single ownership, and the ability to be aliased through &. The &#Int you can hold is not evidence of indirection; it is evidence of an anchor. The pointer feeling is real, but it is the anchor talking, not a box.
Getting this straight reframes the whole kind axis. #T is not T-with-a-box-around-it, a representation trick over the same type. It is a different type that happens to share T’s underlying architecture — its field layout — and nothing else. It has its own identity discipline, and because it is a distinct type it has its own constructors, its own operators, its own methods. The value Int and the reference #Int are as unrelated, behaviourally, as any two nominal types that happen to have the same fields.
The cost of taking that seriously is that there is no free behavioural reuse. If #Int is a genuinely separate type, a method or operator written for Int does not apply to it; only the structure carries over, and behaviour has to be declared again. That is a real price — it is the reason the temptation to treat # as “same type, just boxed” never fully dies — but it is the honest consequence of the identity story, and paying it is what lets the next chapter talk about constructing a # type without incoherence.
Naming a type by its meaning, not by its construction
Once #T is its own type, the immediate question is how you construct one, and that question runs straight into a decision already made for generics: there is no turbofish. A call carries no <> list; a type reaches a constructor by inference off a value argument or as an explicit Type value, never as an angle-bracket channel at the call site (the generics story’s no-turbofish chapter explains why, and the rule lives in generics.md §5). The principle underneath it is worth stating in its own terms: a constructor is called by the type’s identity, not by the architecture it is built from. Vector<Int> names an architecture — Vector applied to the parameter Int — and a use site does not respell that architecture; it writes Vector(…) and lets the Int ride in on the arguments.
Read that way, letting #name be a constructor looks not just allowed but right. The objection to turbofish is that <> smuggles a type’s parameters — its architecture — into the value channel, redundantly with the inference that already carries them. But # is not a parameter. Nothing on the arguments reveals it: an Int(10) argument cannot show whether the caller wanted a value or a cell, so # is not a redundant second channel for information inference already has — it is intrinsic to the type’s identity. By the very principle that kills turbofish, #Int(10) — naming the type you are constructing — is exactly the spelling the rule requires, not the spelling it forbids. We spent real time on this road, and it is a genuinely nice library-API trick: #T as a first-class type you construct by name.
It wobbled on the use-site consequences. Making #name a constructor puts # in call position, so # becomes a mark that can appear wherever a type is used, not only where one is declared — and that reopens everything the first chapter’s “modifier” framing threatened. In generic code a parameter T is sometimes a value type and sometimes a reference type, and the moment you can write #T you are forming reference types out of parameters and mixing #T with #U and with a bare V that is already a reference type, and asking for the meaning of #T when T is already #-marked. The trick that was clean for #Int at a concrete call site turned into a swamp the instant T was a variable. The tension is real and it is left open at the end of this chapter; the next chapter resolves it by attacking the premise — that # should be a use-site mark at all.
Confining # to the body forms
The swamp came entirely from # being applicable to arbitrary type expressions — primitives, named types, parameters. So the resolution is to take that away: # may mark only the three body forms — #struct, #variant, #enum — and a body form only ever appears at a declaration. There is no bare #Int, no #T, no #Vector<Int>; the current spec’s permission for # to compose with a primitive or a named type (syntax.md §2.10) is exactly what gets withdrawn. # stops being a modifier you apply and becomes part of how you declare a reference type.
The consequences cascade, and they are almost all the problems of the previous two chapters dissolving at once. Every reference type is now declared, so every reference type has a type name and therefore a home package — which answers, without a new rule, the question of who may hang constructors, operators, and methods on it. Because the reference type is named, its constructor is the bare name — Node(…), Weapon(…) — and the # never reaches a call site. The #name-constructor idea is therefore not so much rejected as made unnecessary: there is no anonymous #T left that would need a #-bearing constructor, so the whole turbofish-adjacent tension about # in call position simply has nothing to attach to. And the generics swamp drains: T can still be a reference type — you can instantiate a generic with Node — but you can no longer form #T, so the double-#, the #T-mixed-with-#U, the “is this parameter already boxed” questions cease to be expressible. The confusion was never inherent to polymorphism; it was manufactured by a use-site #, and deleting the operator deletes it.
The price is paid in expressiveness, and it is not nothing. You lose the ad-hoc cell: there is no &#Int for a shared, aliasable plain integer; if you want one you must declare a named cell type — type Counter = #struct { n Int; } — and share a &Counter. You lose use-site #-flipping: given a value type you cannot summon its reference counterpart at the point of use, you re-declare the body, which duplicates layout wherever you want both kinds. And there is no generic “reference-ise this T” at all. For a language whose philosophy already holds that value and reference are separate types sharing only structure, making the user name the reference type they need is arguably the honest tax rather than a loss — a shared mutable cell is a concept, and concepts earn names — but it is a real tax and worth naming as one.
One edge is still open where this chapter stops. It is whether an anonymous inline #struct — a reference body that appears as a member’s type without a type declaration to name it — should be allowed at all, or whether reference body forms must always be named so that the “every reference type has a name and a home” property holds without exception. The clean answer is to require the name, but it is a restriction on inline type expressions that needs its own justification, so it is left for the chapter that resolves it; recording it here is the point, so the next reader does not mistake an unfinished edge for a settled rule.
Every type is named, because construction calls it by name
The edge the body-forms chapter left open — whether an anonymous inline #struct must be named — turned out to be the visible corner of a rule bigger and simpler than the question that surfaced it. The honest answer is not “reference types must be named” but every type must be: a direct inline type, written where a type is used rather than declared, is illegal outright. A field, parameter, or return type may only name a type — a bare name, or a named type applied to arguments — never spell a fresh one out in place.
What forces this is construction, the same package-scope, name-based construction the rest of this file already leans on (types.md §3.1). You build a value by writing its type’s name and an argument list; the constructor is a verb named after the type. An anonymous type has no name, so it has no constructor, so a value of it cannot be built the way every other value is — you would need a second, nameless construction syntax beside the first, and a type that can sit in a field but that you cannot refer to anywhere else. That is not an awkwardness at the edges; it is a type sitting outside the construction model. Rather than invent a parallel mechanism to build the nameless types, we removed the nameless types. If a shape is worth using, it is worth a type declaration; once it has that, it is an ordinary named type with an ordinary constructor.
We reached for a narrower line first — ban the inline bodies (struct, variant, and their # forms) but keep the structural type expressions inline, on the grounds that those merely apply an existing builder rather than define a new type (syntax.md §2.4 currently permits both). It reads well until you follow it into construction: an applied generic like Vector<Int> is built by name, but a bare structural shape is not, and drawing the legal line anywhere other than “does this have a name-based constructor” leaves a use site that sometimes names its type and sometimes spells it out. One kind of type at a use site — a named one — is the property worth having, and only the total line delivers it cleanly. The init{ } construction body is so far specified only for structs; how a constructor builds a variant, or any non-struct form, is not yet settled, so this rests on the principle rather than on a particular construction form. However those bodies land, the types they build are reached through a type declaration, not spelled out inline.
The cost is namespace pressure, and it is real. A one-off grouping that a nested language would tuck inline now needs a top-level type and a type name, so a cluster of small shapes becomes a cluster of package-scope names, and the “just group these two fields here” convenience is gone. We take that as the honest tax of a single construction model rather than a regression: a shape common enough to embed is usually a concept worth naming, and the reader who meets the field gets a type name to look up instead of a body to parse. Whether to soften the tax with block- or section-local type declarations — named and nominal, but not raised to the package namespace — is left open; it would keep every type named while letting the name be local, and nothing here forecloses it.
Coercion follows the call, not the store
The last chapters settled how a value gets built — by name, through a constructor. This one is about when the compiler builds one for you: an implicit constructor, inserted silently so that a Feet can satisfy a slot asking for Meters. The machinery itself was never in doubt; where it may fire was, and the pressure that forced the question was plain verbosity. A positional constructor argument coerced — printDistance(Feet(…)) quietly became printDistance(Meters(Feet(…))) — but the field-constructor form did not. So Point{x = 3, y = 4} was rejected where Point(3, 4) was accepted, and you were made to write Point{x = Int(3), y = Int(4)}, spelling out a wrap the paren form spared you. Two syntaxes for the same act — calling a constructor — disagreeing on whether the compiler would meet you halfway.
The first instinct was to read this as a missing feature and reach for a large one: target-typed construction, where a bare {x = 3, y = 4} infers its type from the slot it lands in. That road is real and other languages walk it, but it was the wrong diagnosis — it answers “construct without naming the type,” and the actual complaint was narrower and sharper. A field-constructor call already names its type; it simply was not being treated as the call it plainly is. Once we saw the exclusion as it really was — an inconsistency, not an absent feature — the fix shrank to a single move: make the named field entries of a Type{ … } call coercion sites too, exactly like the positional arguments of a Type(…) call (types.md §4.2). The ()/{} disagreement dissolves because both are now the same kind of site.
The harder question was where to stop, and we did not get it right on the first pass. The obvious next candidates were the other places a value meets a declared type: the init{ } a constructor body writes its fields through, a return, a plain assignment, a declaration. We took init{ } in first, on a tidy syntactic rule — every { field = expr } coerces, whether it is a call at a use site or an init in a body — and it lasted about as long as it took to state out loud. Because init{ } is not the caller satisfying someone’s contract; it is the constructor authoring its own value’s fields, in the very type definition where those field types are written. That is the same posture as a return, which hands a value to the return type you declared, and as an assignment, which stores into storage whose type was fixed at its declaration. Pulling init back out was the moment the real line showed itself.
The line is not “wherever the destination type is known” — it is known in every one of these places. It is whose type it is. A coercion fires where a value is passed into a call or constructor, adapting to a contract fixed by someone else’s signature; it does not fire where the value is written into a type you declared locally — a symbol declaration, an assignment or store, a return, or the fields your own constructor builds through init{ } (types.md §4.2). Field-constructor call entries sit on the first side, and that is the whole of the change; init, return, assignment, and declaration sit on the second, and stay explicit. One test, applied honestly, sorts every position.
match is the satisfying check on that test, because it needed no new rule at all. The scrutinee is never coerced — you dispatch on the value’s live tag, so you must already hold the variant, for the same reason a method receiver is never converted (types.md §4.6). And an arm body is a return in disguise: => expr is shorthand for { return expr } (adt.md §5.1), so an arm whose value differs from the match’s result type must wrap it explicitly, precisely as any other return does. Coercion still fires inside an arm, at the ordinary call boundaries there — but the arm-to-result handoff is the return side, and stays explicit. A construct we never once mentioned while drawing the line already obeys it.
The price is a papercut you can see. Point{x = f} at a call coerces, and init{ x = f } in the body beside it does not, though the two read almost identically; a reader has to know that the type name in front of the brace makes one a call and the other a store, and that is a fine distinction to hang a behavioural difference on. We think it is the right papercut — it is the visible edge of a line worth having, and the alternative was a syntactic rule that was easier to state and wrong — but it is a real rule to learn, and pretending the two braces look different would be dishonest. The other unpaid bill is the literal that started all this: { val = 3 } only loses its wrap if the core numeric types expose their concept-to-Int constructors as implicit, and whether a bare literal should lower against any locally-known type is a separate lever we deliberately left on the bench rather than solve under cover of this change.
Naming the moulds, and marking every one
Confining # to the body forms left the language with four constructs that give a type its shape — struct, variant, enum, and tuple — and no single word for the group. We had been calling three of them the “body forms,” but that label was doing sly work: it never named “the forms with a body,” it named “the three the # mark was confined to,” and it quietly shut tuple out while lumping enum in, even though an enum is a bracketed [ ] list exactly like a tuple and nothing like the { } bodies of struct and variant. The set the label named was real; the reason behind its membership was not the reason the name implied.
The pressure that forced the issue was mundane: we needed to talk about the four together — in the spec, and in a compiler’s syntax tree — and a group used on every other page deserves a term. We went looking for one and rejected a few. “Origin form” was accurate — every type, the core types included, is cast from one of the four — but it states the definition instead of lending an image, and a term is not a summary. “Matrix” was the buried gem: in typography a matrix is the mould a piece of metal type is struck in, so it ties straight to the word “type” the language already uses — but a programmer already holds “matrix” for a math object and a container, and a term that has to fight its own reader every time it appears is a bad term however clever the etymology. “Arche,” the Greek for a first principle, was too exotic to read naturally on the third line of a spec paragraph. We landed on mould: it keeps the exact casting metaphor “matrix” carried — the form a type is cast from — with none of the baggage, and it pairs with the existing verb in register, so the language now has a plain word for the constructs that shape data beside the plain word for the constructs that do work.
Naming the four as peers is what exposed the tuple gap as the accident it was. If value-versus-reference is genuinely one axis orthogonal to shape — the claim the whole two-axis model rests on (types.md §2.1) — then every shape should cross it, and singling tuple out is a dent in the very orthogonality that makes the single # modifier elegant. We looked hard for a real reason to keep tuple value-only, and the best reason is a nudge, not a wall: a reference type has identity and is aliased through &, and the moment a product is important enough to carry identity its fields are arguably important enough to name, so a reference product ought to be spelled #struct and #tuple is a positional, worse-read spelling of #struct. That is a genuine ergonomic argument. But it is style advice, and we were letting it masquerade as a grammar rule — while the grammar already contradicted it, since #enum exists and an enum is a bracketed list no more “bodied” than a tuple. So we removed the carve-out: # marks any mould, #tuple included, and a reference tuple is just a positional reference product placed by the ordinary reference-type rules (memory.md §3.5). With every mould now taking the mark, “body forms” and “mould” named the same set, and the older label — always the weaker term — was retired.
The cost is the nudge we gave up. Nothing now steers a writer away from #tuple[Int, &Self] toward the #struct { head Int; tail &Self } that a reader would usually thank them for, so the language permits a positional reference type that is rarely the best choice, and “name your fields once a product has identity” drops from an enforced line to advice a style guide has to carry. We think that is the honest trade: buying back the orthogonality of the two-axis model — one mark, every shape, no exceptions to memorize — is worth more than a forcing function the grammar was enforcing by accident and only three-quarters of the way.
The tuple was a product we already had
The previous chapter talked itself into a corner it did not quite see. It had spent its length arguing tuple into full peerage — # marks every mould, tuple included, for an orthogonality the two-axis model wanted to keep clean — and then, in its last paragraph, named the price with unusual candor: nothing now steers a writer away from #tuple[Int, &Self] toward the #struct { head Int; tail &Self } a reader would thank them for. We had written down, in our own words, that the feature we were polishing was one we would advise people not to use. That is not a cost a good feature carries; it is a feature confessing it should not exist.
Specifying construction forced the reckoning. When we finally pinned down how a variant is built — naming a case — we were working from the rule that runs under the whole type system: every constructible type is named, and construction is the purpose of a type name. Held against that rule, tuple was a hole, not a mould. It had a declaration form and nothing else: no literal to build one, no positional access to read one back, and the single consumer that could have given a product-of-values any meaning — match — by design does not destructure it. Every other mould earned its keep by the operations on its values; tuple earned its keep by being a shape in a table. Strip the orthogonality argument away and what remained was a positional product — and a struct is a product with its fields named, the same shape done better in every case a reader has to live with afterward.
We looked at finishing it rather than cutting it. Give tuple a literal and an access syntax — positional .0, .1, or the 1-based counting the rest of the language uses — and it becomes a usable type. But that walks straight back into the ergonomics the previous chapter had already called worse, now with more surface to specify, and it would have to reconcile positional field access with the no-destructure stance the multi-scrutinee rule leans its whole weight on. Keeping it inert — nameable but unbuildable — was the other option, and it fails the naming rule outright: an unconstructable mould is exactly the dead corner “every constructible type is named” exists to forbid. So we dropped it. There are three moulds now — struct, variant, enum — and the one place the spec had used a tuple, a QualifiedIdent of two strings, is a two-field struct that reads better than the pair it replaced, which is the whole argument in miniature. Nothing rhetorical is lost: the multi-scrutinee block still forbids parentheses because they would name a tuple to take apart, and you need no mould in the language to reject a concept — Rust’s Result is named in the spec the same way, as a foil, without being part of Zane.
The cost is the orthogonality we had bought one chapter earlier and now hand back. “One mark, every shape, no exceptions to memorize” was a real elegance, and the mould set is no longer the tidy cross-product of {value, reference} against every shape — it is three shapes that each cross the # axis, with a fourth shape simply not there. But an orthogonality maintained across a shape we would tell no one to use is symmetry for its own sake, and paying for it with a whole construct — one more keyword, one more entry in every mould list and summary, one more construct a reader of the grammar must hold — is a bad trade we had made mostly because the symmetry looked clean on the page. Fewer moulds, each pulling its weight, is the honest shape of it. What we truly give up is the terse positional product for the rare moment someone wants a bare pair and would rather not name its halves; they write the struct and name them, a few more characters and a better line for whoever reads it next.
Named constructors, and the syntax variants already had
A type usually has more than one construction path. A Vector2 is built from its x and y, but it is also, meaningfully, “the origin,” or “a diagonal of length n,” or “the point at polar (radius, angle)” — and the anonymous by-type-name constructor can distinguish those only by the shape of their arguments. Overloading carries you a short distance: Vector2(Float, Float) and Vector2(Float) are distinct because their arities differ. But two paths of the same shape — fromCartesian(x, y) and fromPolar(radius, angle), both two Floats — collide, and even where arities differ, the call site Vector2(Float(0), Float(0)) says only “two floats,” never “the origin.” The intent that lives in the name of a construction path had nowhere to go.
Dart’s answer is named constructors — ClassName.named(...) — and we took it because that pressure is real and the addition costs almost nothing. The idea had been logged as #124, but a standing request is no justification on its own; what earns named constructors their place is the construction paths overloading cannot distinguish. Naming a verb after a type was already the marker that made it a constructor (implicit return, init{ } unlocked); all a named constructor does is let that name carry a .suffix, the same two unlocks with the suffix only distinguishing which path this is. We rejected the alternatives quickly: a separate static-method or new-keyword syntax would mint grammar for a case the marker model already covers, and Zane spends its budget avoiding exactly that; keeping overloading-only would leave the same-shape paths permanently unnameable. The casing rule does the disambiguation for free — Vector2.zeros has an uppercase receiver, so .zeros is a member of the type and reads as a constructor, while v.zeros is a member of a value and reads as a field or method. Nothing new had to be taught.
The addition landed now rather than as its own separate feature because variants had, one design over, just introduced the exact surface a named constructor needs. Building a variant is naming a case: Expr.intLit("5"), a Type.member(args) form, in both the long e Expr = Expr.intLit("5") and the short e Expr.intLit("5") declaration. A named struct constructor is spelled identically — v Vector2.diagonal(Float(3)), long or short — so instead of designing a second syntax we reused the syntax already on the page. That is the whole of the connection, and its size matters, because the tidy overclaim is right there and it is wrong. It is tempting to say a variant case is the built-in named constructor of a sum, one mechanism in two hats. It is not. A named constructor is a verb — you declare it, give it a body that runs, overload it, and it builds through init{ }. Naming a variant case is built-in syntax with no verb behind it: nothing is declared, nothing generated, the case names itself. They share a spelling and diverge underneath, so the record should use rhymes with, never unifies — the syntax is one, the machinery is two.
The cost is small and we will name it anyway. There are now two spellings for “make a Vector2 by a particular path” — an anonymous overload told apart by argument shape, or a named constructor told apart by its name — and the grammar does not pick between them; a writer does. When two paths have distinct shapes, either works, and “name it or overload it?” becomes a style call the language declines to make for you. We think that latitude beats a rule forcing one or the other, but it is real, and a house style ends up settling it rather than the compiler.
Naming the last shape: the peer mould
Dropping tuple left a smaller loose end than the feature itself, and we did not see it until the set had shrunk. Of the three moulds now remaining, two were named by their shape — the product struct, the sum variant — and the third, enum, had only ever been “the other one.” While tuple was also unnamed the gap was invisible; once enum was the lone shape without a name of its own, the asymmetry was conspicuous, and a category the spec talks about on every ADT page deserved better than a placeholder.
That it is a real category, and not just an underspecified sum, is a point worth making carefully, because the tidy dismissal is wrong. A variant’s representations count as the sum of its cases’ payload cardinalities; an enum’s members carry no payload at all, so its count is simply the number of members. You can call that a degenerate sum — a sum of units, 1+1+…+1 — and be technically right, but the degeneracy is the distinction: a shape whose members have no interior is a different structure to reason about, tabulate, and iterate than one whose members each carry a type, which is exactly why the language keeps enum and variant apart in the first place. It earns a term for the same reason it earns a keyword.
Finding the name took a couple of wrong turns worth recording, because each was tempting. The first was scalar, from the cardinality framing — product multiplies, sum adds, and this one just counts. Elegant on paper, and dead on arrival at the reader: “scalar” means a single primitive value in nearly every language a Zane user will have met, the very opposite of a set of n constants, and a term that fights its own reader is one we had already refused once when we turned down “matrix” for mould. The second was case, naming each member a case — but “case” was long since spent on a variant’s members, where a value holds one case and match selects them, so lending it to enum too would smudge the one line the whole two-construct design exists to keep sharp. We took a genuine detour through probability, where an enum really does look like a sample space Ω — a finite set of mutually-exclusive, exhaustive, atomic outcomes — but “outcome” and “event” drag in randomness and measure an enum has nothing to do with. What every dead end had circled was the same property: the members are atomic, structureless, equal in rank. And the language already had a word for that, sitting in the enum chapter since it was written — its members are “uniform, interchangeable peers.” So peer mould was less coined than promoted: it names the category from the enum’s own defining trait, collides with nothing, and imports no baggage.
The honest note is what the name gives up next to its siblings. “Product” and “sum” advertise an operation — ×, + — and “peer” does not; it describes the members, not an arithmetic. But that is the truthful trade, because the enum’s shape is not a third operation beside the other two, only the all-units corner of sum, and a term implying an algebra it does not extend would be the same overclaim we spent the naming on avoiding. peer mould names the category’s nature — a flat set of uniform peers — and leaves the arithmetic to the two shapes that actually have one.
Unit becomes an ordinary type, and core leaves the package model
The question arrived through a generic field. If Player<T> carries optional extra settings, Player<Void> is the obvious application when there are no settings to carry. But the field still has to be constructed: what value can be passed for a type that exists only as a return-position marker? That pressure made Void an actual zero-sized type with an actual constructor, Void(), so its value could sit in a symbol, field, array, or type argument like any other value. Once it had exactly one value, the old name no longer described it — a void has none, while a unit type has one — so we renamed it to Unit, making the final application Player<Unit> and its field value Unit(). The rename records the model’s new shape and leaves Never as the natural future name for a type with no values.
A user can already declare an empty struct, which forced the sharper question: what distinguishes Unit from MyUnit? Layout does not. Both may take zero bytes, both have one logical value, and both constructors are ordinary verbs supplied by their defining package. We initially tried to privilege Unit anyway: reaching the end of a Unit verb and bare return would synthesize Unit(). That looked harmless because there is only one result, but it required the return checker and AST lowering to recognize one nominal type and invent a call for it. The comparison with Bool in an if did not save the exception. An if already has to check its condition against some destination type; naming that type Bool changes no unrelated rule. Synthesizing Unit() would add behavior that returns do not otherwise have.
So Unit receives no completion privilege. A verb returning it writes return Unit(), and abort and resolve paths write the same value explicitly. This makes the return checker uniform and keeps the bundled constructor observable as an ordinary constructor rather than a compiler rewrite. The cost is familiar procedure boilerplate: an operation with no informative result still spells the sole value at every returning path. We accept that cost because the alternative would make the type ordinary everywhere except the AST node where uniformity matters most.
Following that distinction led past Unit into the types surrounding it. We had been calling Int, Float, Bool, String, and Void ordinary types from an ordinary core package, while giving the compiler no way to treat them as ordinary. Conditions already required Bool; counted loops already required Int; literals lowered toward these names. The package claim was not an abstraction the language actually honored. It was a layer of qualification drawn around types whose identities the language syntax already required.
We considered exposing the storage primitives instead — unwrap Bool(true)._v for an if, unwrap Int(20)._v for a loop — and rejected it because it turns representation into semantics. A field rename would change what control flow accepts, every API returning Bool would need manual unwrapping, and abstraction would end exactly where the language needs it most. The resolution keeps core as the compiler’s implementation package while removing it from the source package model: the five fundamental names are predeclared, their definitions ship with the compiler, and @primitives$ remains below them as storage machinery. The cost is a deliberately privileged implementation package, but not five compiler-defined type bodies or constructors. Bool and Int are named by the control-flow type rules; Unit is merely another bundled declaration.
No exception for the bare literal
The chapter on coercion settled where an implicit constructor fires and then left one bill unpaid, in as many words: whether a bare literal should lower against any locally-known type was a separate lever, and we put it on the bench rather than solve it under cover of that change. It came off the bench the moment we looked at what the spec was actually written in.
The spec was using the lever that its own rules disclaimed. text String = "" stood in the memory rules as a legal declaration; a field constructor initialized damage Float = 10; a lambda body assigned this.shooting = false. Every one of those is a declaration or an assignment — positions the coercion chapter had named explicitly as not coercion sites — and every one of them relies on a bare literal turning into a fundamental type on the way in. The rule and the examples had contradicted each other since before either of us noticed, which is the ordinary way a deferred question announces that it is no longer deferred.
Our first answer was to make the concept type the exception, and it had a genuinely good argument behind it. A compiler concept type has no storage form at all: it may sit in a parameter position and nowhere else, so a concept-typed expression cannot come to rest anywhere in a program. Some conversion has to turn it into a storable value. If it cannot be stored, then it must lower into whatever type its destination fixes, and a declaration fixes one just as firmly as a parameter does. Read that way the exception is not a widening of the coercion rule but a consequence of a fact about concept types, and it leaves the ordinary case untouched — distance Meters = Feet(...) stays illegal, because Feet has a storage form and needs no rescuing. We wrote it down that way, and it survived one round.
The question of what it actually licensed killed it. Two lines at the same syntactic position now behaved differently, and the property that separated them was not visible in either line: whether the source expression’s type happened to have a storage form. That is precisely the two-tier behaviour the one test was written to abolish — the test asks whose type the destination is, and the exception answered a different question underneath it. Worse, it did not stay small. Array and map literals are concept-typed too, so the exception legalized a List<Int> = [Int(3)] and its map equivalent, quietly making declarations a coercion site for whole containers. In practice, our narrow observation about scalars became “declarations are not coercion sites, except when they are.”
So we took it out entirely, and we took it out for maps and arrays as well as for numbers and strings, because the whole value of the rule is that it does not have a second tier. A declaration, an assignment, a return, and the init{ } a constructor writes its fields through are not coercion sites for anything at all (types.md §4.2). The spec’s own examples had to move: text String(""), damage Float(10), this.shooting = Bool(false). Where no destination type is fixed for a literal to lower into at all, it is wrapped at the point of use instead (generics.md §5.4). The round trip was worth taking rather than embarrassing: the exception was the most plausible version of the idea, and watching it grow from one legal line into container-wide lowering is the argument against it that no amount of staring at the original sentence would have produced.
The same round added a position to the list rather than removing one. An enum map declares a property across an enum’s members — <Enum>.<property> <VarType> { member = value; ... } — and its entries are coercion sites (adt.md §6). The header states the property’s type once, and each entry fills that already-stated slot, which is the same shape as a field-constructor call entry: the contract is fixed outside the expression being written, and the entry is supplying a value into it.
That is worth stating carefully, because the earlier chapter’s phrasing does not obviously reach it. That chapter drew the line at a contract fixed by someone else’s signature, and an enum map’s header is one you wrote yourself, in your own declaration, a few characters to the left. By that wording it belongs on the store side. But authorship was never the operative criterion — it was a description of where the line happened to fall across the positions we had at the time, and the enum map makes the difference visible.
The posture underneath is that coercion should fire wherever it can. Every position that carries a literal to its destination without ceremony is one the language does not have to charge for, so the question is never “why should this one coerce” but “what are we deliberately keeping out”. The answer is narrow and specific: a runtime symbol. A declaration and an assignment name storage that exists while the program runs and outlives the expression written into it, and those we exclude on purpose — that is the carve-out the previous chapter was really drawing around, and return and init{ } are the same kind of position seen from the inside of a constructor or a signature.
An enum map is not that. It is part of a type declaration — static, exhaustive, access-only, with no value form at all and nothing to dispatch over (adt.md §6). There is no runtime variable anywhere in it for the carve-out to protect. So it coerces for the same reason most positions do: nothing stopped it. The rule as types.md §4.2 has stated it since the fundamental types landed already had room for this — a contract whose destination type is fixed by a callable or language construct — and the enum map is the first language construct to take it up.
The cost of an exceptionless rule is exactly the verbosity the exception would have bought off, and it is not nothing. text String("") is heavier than text String = "", the wrap is pure ceremony in the cases where the destination type is written on the same line, and this is the most common shape in the language — a local, with an annotation, initialized from a literal. We accept it because the alternative is a rule with a clause in it, and a reader has to carry a clause around forever. One test that sorts every position is worth more per line than the characters it costs at each one.
How a literal lowers into primitive storage
The chapter on Unit left @primitives$ below every declared type as storage machinery, and the literal-concept split in the generics story gave each kind of literal a concept type of its own. Between the two sat a step nobody had written down. A literal carries a concept type, a concept type has no storage form, and a type that holds a number is built over a primitive that has one. Some operation has to turn 20 into a @primitives$Int, and nothing in the language did. The spec described a literal arriving at a conversion and described the primitive underneath, and the constructor bodies that would have had to bridge them were written as the ... placeholder.
There were three ways to close the gap. The compiler could treat the step from concept to primitive as a built-in conversion of its own, but the coercion rule states that literal coercion is the ordinary implicit-constructor algorithm and not a separate compiler-only lowering, so that road would have reopened a special case we had already removed. The compiler could supply a named conversion intrinsic, such as @primitives$IntFromConcept, one per pairing of concept and primitive. Or each primitive could accept its literal directly, as a constructor. We leaned towards the named intrinsic first.
Naming it is what reopened the concepts’ own names. The generics story had turned down @concepts$Int and @concepts$Float for two reasons: a concept should not borrow the name of a storage type that a package declares, and “float” names a binary storage format while 2.5 is exact decimal digits. Looked at again, the first reason did not hold. A concept always carries its @concepts$ prefix, so it cannot be mistaken for any package’s Int, and sharing a word is an advantage rather than a hazard: it shows which intrinsics belong together, and the names are the names programmers already use. The container concepts had followed this all along — @concepts$Array beside @primitives$Array, and @concepts$Map — and only the scalar concepts had not.
We considered making the rule “a concept is named after the primitive it lowers to”, and settled on a different one: a concept is named after what that literal is usually called in other programming languages. The literal 3 is an int, 2.5 is a float, and "a" is a string almost everywhere, so the concepts became @concepts$Int, @concepts$Float, and @concepts$String (syntax.md §2.8), and the prose followed, so a literal with a . is now a float literal. The rule does not depend on a primitive existing for every concept, which is why @concepts$Map fits it with no @primitives$Map in sight. The spelling rule did not move: 3.0 is still a float literal because of how it is written, whatever its value.
With the concepts renamed, the named intrinsic read badly. Its name had to distinguish a concept from a primitive that now shared a word, and every candidate came out as some form of @primitives$IntFromConceptInt. The constructor expressed the same conversion with nothing added: @primitives$Int(value @concepts$Int) builds the Int primitive from the Int literal. So we took the constructor, one for each of @primitives$Int, @primitives$Float, and @primitives$String, each taking the matching concept (types.md §2.7).
The concept types are not a stage a literal passes through on its way to some package’s type; they are the literals, and @concepts$Int is only the name Zane gives to the type of 20. That settled whether the constructors should be implicit, and the answer was no. 3 is already a value of @concepts$Int, so @primitives$Int(3) is an ordinary call whose argument matches its parameter, with no conversion anywhere in it. A verb that takes a literal declares that in its signature, by taking the concept type itself or a type that declares an implicit constructor from it, which is why a package’s Int accepts 20: it declares that constructor, and its body calls the primitive’s. We did briefly mark the primitive constructors implicit, so that @controlflow$repeat(3, ...) would take its bare 3, and took it back. It would have made the primitives the one set of types that accept literals without declaring so, a conversion no package wrote. The primitives stay underneath every package without taking part in any package’s conversions (types.md §2.7).
A literal is known at compile time, so its size is too, and a literal its primitive cannot hold is a compile-time error rather than a value that wraps or saturates at run time. 99999999999999999999 passed where a @primitives$Int is expected is rejected where it is written, and so is a float literal too large for any finite @primitives$Float.
Two of those primitives had never been named. @primitives$Float joined @primitives$Int and @primitives$Bool as a machine-word scalar without much to decide. @primitives$String needed a shape, and we made it a string view: a pointer to the string’s first byte in the dynamic region and its length in bytes, with no terminator after the last byte. It is a reference type, like @primitives$List<T>: its bytes are dynamically sized and live in the dynamic region, and what sits in the fixed-size region is the handle that names them. A terminator would tie every string to the one convention C uses; leaving it out keeps the string flexible and puts termination on the consumer that needs it. The console is the one consumer the compiler supplies, and it writes exactly the view’s length, so it needs nothing added (effects.md §6.6).
The costs are in the names, the range, and the view. A package that declares a fixed-point or decimal type takes its input as @concepts$Float, a term that describes a binary format its values never use; we accepted that for a term every programmer reads correctly on the page. @concepts$Int beside @primitives$Int beside a package’s Int is three types with one word, told apart only by their prefixes. @primitives$Int is a machine word, so the range check is only as fixed as the word: a literal that fits on one target can be rejected on a narrower one. No intrinsic takes a bare literal, so @controlflow$repeat is handed @primitives$Int(3) or a type that converts to it, never 3. And a consumer that does need a terminator, such as a C function, has to copy the bytes to add one, where a terminated representation would have handed them over as they are.
Text without identity
Interpolation made the boundary between a literal and its stored text worth looking at again. The proposal was a language feature: the compiler resolves the name in \%name and copies its primitive value into the string concept. Leaving the name as plain text for a callee would not do that, because the callee does not own the caller’s scope. We also wanted ordinary strings to reach the primitive through the implicit constructors packages already declare.
That exposed the classification from the previous chapter. We had called the primitive a string view and made it a reference type because its bytes were dynamically sized. But the size of a payload is not the reason for identity, and the deep-copy model had already given values a means of owning out-of-line storage. We chose to make both String and its primitive values, rather than open implicit conversion to reference-type sources. The source restriction stays where it was; strings now satisfy it (types.md §2.7).
The primitive keeps a fixed-size handle and unterminated bytes, but it owns those bytes. Calling it a string primitive rather than a view records that ownership; a view would suggest borrowed storage, which is not the contract we chose. Copying text copies the owned bytes, while ordinary value parameters borrow them, so merely handing a string to the console does not copy it. The cost is where the value copy really happens: storing an existing string in another slot copies its contents, just as storing a recursive value copies its children. We did not introduce shared storage or copy-on-write to hide that cost.
The interpolated literal is still a concept. That makes a primitive-to-concept-to-storage round trip possible, and we accepted it rather than making interpolation return a package’s concrete String. A consumer still gets to decide the meaning of literal text; the compiler supplies the copied insertion and the scope resolution. With runtime insertions, a string concept is no longer a leaf compile-time value (types.md §2.8).
The scalar primitives become I32, I64, F32 and F64, converted by constructor
Once the machine operations took operands of a single type (the operators story), a program that adds an integer to a float has to convert one of them first, and nothing in the language could. The first sketch was a conversion intrinsic of its own, such as @primitives$toFloat, which would have worked and would have been a second spelling of a conversion Zane already spells. A value becomes a different type through a constructor of that type: a literal becomes storage through @primitives$Int(3) (the literal chapter), and a package’s types convert through their own constructors. So converting an integer to a float became an overload of the float’s constructor, @primitives$Float(count), beside the overload that takes its literal.
That works in the direction that loses nothing. The other direction cannot be a bare constructor, because @primitives$Int(ratio) does not show how it rounds — toward zero, down, to the nearest — and a reader should not have to look that up to understand a line. The name had to carry the rounding, and Zane already has names on constructors: a named constructor builds the base type and names the method, and ArrayRef.fill had put one on a primitive before. So the lossy direction became @primitives$Int.truncate(ratio), a constructor of the target, named for its loss, which leaves room for a floor or a round beside it when core needs one.
Laying the conversions out pairwise exposed the primitives themselves. The spec named @primitives$Int and @primitives$Float; the compiler had added I32 and I64 beside them, and its Int was an I64 under a second name. Two names for one storage is a duplicate, and a name that hides its width hides exactly what the conversions are about: whether a value survives depends on how many bits each side has. So Int and Float left the primitives, and the scalars are I32, I64, F32, and F64 (syntax.md §2.7). Int and Float remain the names of core’s types, whose declarations fix their own width underneath. A literal took no width with it, because a literal never had one. 7 is a value of @concepts$Int, and the concept is what it stays; the constructor it is handed determines its storage, so @primitives$I32(7) and @primitives$I64(7) are both legal, and each checks the range of its own primitive (types.md §2.7).
With four scalars there are twelve conversions, and one rule sorts them: a conversion is the target’s anonymous constructor only when it is exact for every value of its source, and a named one otherwise (types.md §2.9). Applying the rule took more care than stating it. I64 to F64 looks exact — both are 64 bits — and is not: a double’s significand holds 53 bits, so above 2⁵³ the doubles skip integers, and 2⁵³ + 1 becomes 2⁵³. Only three conversions survive the test: I32 to I64, F32 to F64, and I32 to F64, whose 31 bits of magnitude fit in 53. The other nine are named. wrap keeps an integer’s low bits, truncate drops a float’s fraction, and round takes the nearest value the target holds, in one step from the source, since rounding an I64 to a double and then to an F32 can land on a different F32 than rounding it once. Nearest left one case open, a source exactly halfway between two targets. We took IEEE 754’s round half to even: the scalars are already IEEE 754 floats, it is the rule every mainstream processor and backend applies unless told otherwise, and a tie that goes up as often as down does not push accumulated error in one direction. A float whose integer part does not fit, or a NaN, has no truncation at all. The first draft had truncate stop the program there, the way the compiler then stopped at an integer division by zero, and we took that out together with the division’s stop, for the reason the operators story gives: truncate now holds the result to the target’s range, its least or greatest value, and a NaN becomes zero, as in Rust’s float-to-integer conversion.
The costs are in the length and the count. Four names stand where two did, and a package that declares Int now chooses which of two widths it is built on. A conversion is always written, and the lossy conversions spell out their loss at length: @primitives$F64.round(count) for an I64 that is in practice small enough to be exact, where a looser language would convert without comment. We accept that because the long form is the honest form; the wordiness lands on core, which is written once, and not on the programs written over it.
Reading a number from text is a method, because it can fail
The runtime’s arguments hands a program its arguments as strings, and the first program to read them wanted a number. Converting a value to a different type is the job of a constructor of that type, which is how the scalar conversions came out, so the first spelling we reached for was a named constructor, @primitives$I64.parse(text), beside truncate and round.
It does not fit, because every one of those conversions has a result and reading a number does not. "12x" spells no integer, and "99999999999999999999" spells one that @primitives$I64 cannot hold. The call has to fail, and in Zane failure is an abort, which a constructor cannot do: a constructor’s written type name is its return type, and there is no place in it for an abort type. We considered adding one. The spelling was the smaller problem. A named constructor would have had to split its name around the abort type or hang it after the name, and neither reads as one name. The real problem was implicit constructors. An implicit constructor runs at a coercion site, where the call is not written (types.md §4.2), so an implicit one that could abort would have had nowhere to attach the handler every abortable call must carry. Either a coercion site could hide a failure, or constructors would split into two kinds, the constructors that may be implicit and the constructors that may abort. We kept one kind: a constructor always gives a value of its type.
So reading a number is a method of the string primitive, parseI64 and parseF64, each aborting with @primitives$Unit when the text is not a number or the number does not fit (types.md §2.10). The text they accept is the text of a literal, with an optional - in front, and nothing more: no whitespace, no +. That makes the rule one a reader already knows, since what parses is what could be written in source, and it leaves trimming and other forms to the program that wants them.
The cost is that converting no longer has a single spelling. A conversion that cannot fail is a constructor of the target, and one that can is a method named for its target, so a reader learns two forms where the scalar chapter had offered one. We accepted that because the line between them is the line a caller has to care about: the method form needs a handler. The strict form costs too. " 42" aborts, and a program reading untidy input trims it first.
@primitives$String.escaped reads text escapes when a consumer asks
Interpolation reached the compiler, and with it the rule the lexical story had set for literal text: the language reads the escaped quote, the escaped backslash, and \%name, and leaves every other backslash sequence for the literal’s consumer. The compiler had not been keeping that rule. Until interpolation it decoded \n, \t, \r, and \0 itself, a stopgap from before the spec stated any rule for escapes, so @primitives$String("\w+") arrived as w+ and "done\n" arrived with a line feed. Making the compiler honest about the first case broke the second. Once the plain constructor kept its text as written, "done\n" printed a backslash and an n, and every program that ended a line had written exactly that, core’s println among them.
Putting the decoding back into the plain constructor was the obvious repair, and it was the decoding we had just removed. It would have made the consumer’s part in the lexical chapter a fiction for precisely the sequences people write most: a regex constructor taking the concept would have received a tab where its author wrote \t, and the double escaping that the consumer model existed to avoid would have come back for every pattern with a \n or a \t in it. The other easy road was to leave escapes to nobody and write a real line break between the quotes, which the lexer already accepts. It puts an invisible character in the source, one that an editor’s whitespace settings and a CRLF checkout can change without anyone touching the line, and nobody can tell a tab written that way from spaces. A general escape language in the lexer was the design the lexical chapter had turned down, and nothing about the problem had changed that verdict.
What settled it was a sentence we kept coming back to: “every function should decide what it wants to do with the string.” So there are two compiler-provided constructors where there was one. @primitives$String keeps the literal as written, and the named constructor @primitives$String.escaped reads five text escapes, \n, \t, \r, \0, and \\, in the literal’s fragments (types.md §2.7). A named constructor on a primitive was already Zane’s spelling for a second construction path, as ArrayRef.fill and I64.truncate had shown. A package’s constructor taking @concepts$String calls whichever of the two its author intends. core’s String picks escaped, so ordinary text reads the way programmers expect from every other language, and a regex package picks the plain constructor and gets its backslashes intact (lexical.md §7.1).
It had to be the compiler’s constructor rather than a wrapper core wrote over the plain constructor, because only the compiler can see where a fragment ends. Once the fragments and the interpolated values are joined into one string, a backslash a value brought in looks exactly like one the literal’s author wrote, and reading escapes after the join would read both. escaped reads the fragments and copies each value as it is, for the reason interpolation is not rescanned: inserted bytes are data, not source. \0 needed no special case either. It is a zero byte like any other, since a string carries no terminator for it to be mistaken for (the text chapter).
The cost lands on the backslash. The literal’s structure reads \\ first and escaped reads it again, so text built through core’s String that wants a backslash followed by an n writes \\\\n, four backslashes, the double escaping we set out to avoid, returning for that one case. The set of escapes is the compiler’s and closed: a package that wants \u{…} or \x41 still has to read them itself. And the plain constructor’s name gives no hint of the decoding it skips, so a reader of @primitives$String("\n") has to remember that the literal holds two bytes.
core gains I32 and F32 as storage types, and Int stays the default
The scalar chapter left Int and Float as core’s names, each choosing its own width underneath, and core chose @primitives$I64 and @primitives$F64 and offered nothing narrower. That held until a program stored a lot of small numbers. Porting the LangArena benchmarks put millions of maze cell indices, graph vertex ids and suffix ranks into lists, every one of them far below 2³¹ and every one of them eight bytes wide. The language had a narrow integer, @primitives$I32, but a program could only reach it bare, with no operators, so the narrow layout was there in the primitives and out of reach for ordinary code.
The tidy answer was to name every width: rename Int to I64 and Float to F64, and put I32 and F32 beside them, so that core mirrors the primitives one to one. We turned it down for the people who will write most Zane. A program needs a standard integer and a standard float either way, and Int reads better than I64 in code that is not about bits. Most of the people writing that code will not know or care whether a counter is thirty-two or sixty-four bits wide, and nothing in their program should force the question. So the default has to exist, and it has to be the wide type, because every program that works with an I32 also works with an I64, and not the other way round. A beginner who never considers width then never runs out of range over an unnoticed choice. That is the scalar chapter’s decision applied again: the width belongs in the primitive’s name, and core’s everyday names stay free of it.
The other road was to make I32 a peer of Int, with its own loops, its own list indexing and its own overload of every container method. That would have doubled core’s surface and spread width through ordinary code: a program that computed in two integer types would meet a conversion wherever they met, and with two equal integers those places are everywhere. So I32 and F32 are storage types. They carry the same operators and literal overloads as Int and Float, so a program compares and updates stored values where they sit, and core converts between them by constructor, as the scalar rule does for the primitives (types.md §2.9): Int(x) widens exactly, and I32.wrap says what it loses. There are no I32 loops and no I32 indexing, so a program counts and indexes in Int and narrows only what it stores.
The first release with the new types broke programs that never mentioned them. Float(3), String(5), abs(3) and sqrt(2.0) stopped compiling, because a bare literal now converted to two parameter types where it had converted to one, and the compiler does not choose (generics.md §5.4). Making the compiler prefer Int would have put a fact about one package into the language, and the language names none of core’s types. The repair was already in core: its operators had long declared an overload on the literal’s concept type for each operator, so x + 1 finds Int +(Int, @concepts$Int) without a conversion. The next release did the same for every function that has both widths, and each such overload builds the default type: abs(3) is an Int, sqrt(2.0) a Float (types.md §2.6). Writing that down also corrected the spec, which still stated that Float(2) was a type error. It had compiled all along, by way of Float(Int), and the concept overload now states it directly.
The costs fall in two places. core carries more: every function over both widths needs a third overload for literals, and we have to keep up the pairing as we add functions, or the ambiguity returns for whichever one we miss. Programs pay at the boundary between storage and arithmetic, where a program widens each value it reads from a List<I32> before indexing with it or adding it to an Int. On large bounded data that boundary was cheap and the halved footprint was not: in the LangArena port, maze breadth-first search ran in half the time and graph A* in two-thirds. On Game of Life’s eight-entry neighbor lists it was the other way round. Those lists saved little memory and widened on every read, the benchmark ran up to a third slower, and the port went back to Int. So I32 is a choice a program makes per data structure and checks by measurement, not a default to reach for, which is the place we wanted it to have.
core gains U8, a byte that is stored and never computed with
The I32 chapter narrowed integers to four bytes, and the LangArena ports that worked on bytes still had nothing narrower. Burrows–Wheeler, Huffman, LZW, Base64, CRC32 and the Brainfuck tape all read and write bytes, and core had no type for one. The ports kept their bytes in arena$Buffer, a C struct behind a handle, because a List<Int> spends eight bytes on each. The Burrows–Wheeler decode loop ran 20 instructions per byte against C’s 5. Each push stored a uint8_t through the C struct, and a store of that type may alias anything, so every iteration reloaded both handles and each buffer’s size, capacity and data pointer from memory.
So the primitives gained a byte, @primitives$U8, and core a U8 over it (types.md §2.6). It is unsigned, because a byte is read as a number from 0 to 255 everywhere one is met: in a file format, in a character code, and in C’s uint8_t. A List<U8> holds one byte per element, in Zane memory the compiler can reason about, and the decode loop fell from 450 million instructions to 290 million, against C’s 264 million.
The question was how much of an integer a byte should be. A peer of Int, with its own arithmetic, would overflow at 255 in nearly every sum a program wrote over bytes, and either the overflow would wrap silently or every operation would need a rule of its own. Instead we took the I32 chapter’s answer further: I32 is a storage type that keeps its operators, and U8 is a storage type with none but == and <. A program converts a byte with Int(b) to compute with it and stores the result with U8.wrap(i), whose name shows that it keeps only the low 8 bits. That is the scalar chapter’s conversion rule applied once more: @primitives$I32 and @primitives$I64 take a byte exactly, through their anonymous constructors, and the way back is named for its loss (types.md §2.9). With no arithmetic, the byte is not a scalar primitive: no @math$ function takes it, no float converts to it, and @operators$ gives it only equal and lessThan (operators.md §2.6).
Bytes that live in a List<U8> are the bytes a C library wants, so the byte crosses into C as well. It corresponds to every 8-bit C type, signed ones included, as @primitives$I32 already corresponded to uint32_t: both signs carry the same bits, and Zane reads them unsigned, so a signed char of -1 is the byte 255 (ffi.md §3.3). An @primitives$Array or @primitives$List of @primitives$U8 crosses as a view, and a C-compatible struct may hold the byte primitive.
The costs are the conversions and the measurements. A program writes Int(b) at every read it computes with and U8.wrap at every store, where a language with byte arithmetic writes neither. And a byte list is not faster everywhere. Huffman’s encoder ran in 0.86 of its time on U8, while its decoder, whose inner loop compiled to the same instructions either way, ran 1.31 times slower for a reason the instruction counts did not show, and that port kept its Buffer. Like I32, U8 is a choice a program makes for its stored data and checks by measurement.
The string primitive’s bytes and numbers are specified, and a byte set becomes its own primitive
The U8 chapter gave core a byte, and the same LangArena work gave the string primitive the methods that read one. core cannot write byteCount or byteAt out of anything else the primitives offer, since a string primitive’s bytes are reachable only through its own methods, and its regex package and hash tables needed hashBytes, parseF64At, byteSet, findAny and findPair to be fast enough to use. Every one of them existed out of necessity. They were marked as an experiment in the compiler, though, and the spec described none of them, nor how a scalar becomes text. A program’s author could not learn from the spec the result of String(2.5) or the behaviour of byteAt at a position past the end. So we specified each of them as the compiler implements it (types.md §2.10–§2.12).
One of them did not survive being written down as it was. byteSet took a list of 256 flags and gave back an @primitives$List<@primitives$U8>, and the bytes of that list were a lookup table: the 256 flags again, two bitmaps by which a processor tests 16 bytes of text with one shuffle, and a few bytes recording which shortcut fits the set. findAny and findPair trusted the table and checked only its length. Specified that way, the spec would have had to describe the table, which ties the language to the layout today’s search happens to use, or to leave the result unspecified for a list some program had built or changed by hand, while that list still reached the search. We made the result a type of its own instead, @primitives$ByteSet (types.md §2.12). Only byteSet builds one, so a search always reads a table the compiler made, and the spec names only which bytes the set holds. The input changed with it. The flags are always 256, and a fixed-size input belongs in an array primitive, so byteSet takes an @primitives$ArrayRef<T, 256>, which core builds with fill and then marks in place. The cost is one more storage primitive, and a set that no program can inspect or build except through byteSet.
The text of a number is the format the compiler already wrote: an integer’s decimal digits, and for a float the shortest decimal that rounds back to the same value, chosen between fixed and scientific notation (types.md §2.11). Writing the rule out exposed a seam we have left open. A float literal has no exponent, so parseF64 does not read scientific notation, and 100.0 is written 1e2, a text parseF64 refuses. A number written as text is therefore not always one that a program can read back.
Every mould gets constructors
Named constructors left construction split by mould. A struct had constructors, verbs that a package declares and that build through init{ }. A variant was built by naming a case, and an enum value was a member, written Colors.red. Neither had a verb that produced a value of its type. That split did no harm while every program knew which type it was building. It started to matter when we designed a plugin library whose package takes the plugin’s types as parameters. The library had to ask one of those types for its plugin’s metadata before any instance of the plugin existed, so it needed a value of the type to call a method on, and it had no way to make one that worked for every type argument.
We first reached for an enum. The plugin’s type could be an enum, and a total enum map could hold its metadata, but a generic body that reads a map property depends on the type argument being an enum, and the library would then accept no other mould. Asking for a value of the type was the better question, and the language already had an answer for it: a verb named after its type returns a value of that type. Enums and variants can fill a type parameter as well as structs can, so a generic body may request a value from any of them, and two of the three moulds had never been given the marker. So we granted it (types.md §3.1). An enum constructor returns one of the members, Colors() => Colors.red;, and a variant constructor returns a case, Countdown() => Countdown.done(Unit()); (adt.md §2.2, §3.3). Neither one uses init{ }, because neither mould has fields to fill, and for the same reason neither may use the field-header form Type{field T;}, which exists to fill fields; both are positional. A generic body can now write T() for any type argument whose type declares a constructor, and the plugin library asks for metadata with Info():descriptor(), whatever mould Info turns out to have.
The rule that took the most care was naming. Type.name already had two meanings before this change: an enum member (Colors.red) and a variant case (Expr.intLit("5")). A named constructor on an enum or variant adds a third, and if a constructor could share a member’s name, a reader would need every declaration in the package to know whether Colors.red is the member or a call. So a named constructor’s name must differ from every member and case of its type (types.md §3.4), so Colors.background() is legal beside Colors.red and a constructor named red is an error. Naming a case stays as the variants story left it, built-in syntax with no verb behind it; a variant constructor is an ordinary verb that ends by naming one.
The cost is a second spelling for some values. Colors() and Colors.red can yield the same member, and nothing in the language determines which form a program should write. A package that declares an anonymous enum constructor also picks a default member for everyone who calls it, and that choice is one more line its users have to read. We accepted both, because the alternative was a generic library that works for structs only, and that limit would have had no reason in the language behind it.