Stories: Packages
See also:
spec/packages.md— the rules these chapters explain.
The directory is the package
Packages began with two jobs that were already the same boundary in practice: a namespace and a compilation unit. A directory holds the source that belongs together, and its basename is already the name by which that unit is known. We did not seriously consider a separate mechanism that lets a declaration name some unrelated package as its home. If a.zn sits in the httpClient directory, it belongs to httpClient; there is no second namespace assignment inside the file that can override where the file actually lives. All files in that directory compile as one order-independent unit, so a declaration in one file can use another without imports, forward declarations, or concern for file order (packages.md §2).
That made the written package httpClient line look redundant, but its redundancy is the point. Moving or copying a source file is a filesystem operation, often performed outside any language-aware tool. Without a declaration, the file silently changes packages when it changes directories, and several mistakes can follow from that one unnoticed move. Requiring every file to repeat the directory basename turns the line into an assertion: the directory determines membership, while the declaration records where the author expected the file to be. A mismatch makes the move visible immediately instead of allowing its consequences to surface later as unrelated name-resolution or visibility failures. The cost is one line repeated in every file. We accepted that small duplication because a safety check must carry independent information to catch the operation it checks.
The package boundary also became the visibility boundary. Names beginning with _ are accessible across every file in their package and nowhere outside it; the same lexical marker covers types, aliases, constants, verbs, and every other named declaration, while symbol-named operators remain public (lexical.md §4.2). That choice belongs to the lexical privacy story, not a second packages rationale: the directory gives privacy its extent, while the name makes the boundary visible.
A barrier that still joins the name
Once another package enters a file, we wanted every use of it to remain explicit. Importing math makes the namespace available in that file; it does not pour math’s members into the current namespace. A call stays math$sqrt(value), in the spirit of Go’s qualified package access. The extra package name is a small typing cost, and in return every cross-package reference shows the reader its origin without consulting an import list or resolving collisions between identically named members. The current package is the only place whose members can be written unqualified (packages.md §3).
Qualification still left a syntax question. A separator has to signal to the parser, not merely the later name resolver, that its left side is a namespace and its right side is a member. A dot could not carry that fact. In a.b.c, the punctuation alone does not show which pieces are fields and which, if any, cross a package boundary. We considered ::, the familiar namespace separator, but it was visually heavier than the operation deserved and sat too close to Zane’s object:method() call syntax. A cross-package function such as math::sqrt() would make a package boundary look like a doubled method marker.
We chose $ by looking for a single keyboard character that reads as a connection without disappearing or demanding attention. It forms a clear barrier between the two names, yet its width makes the expression look held together; a thin mark such as ¦ split the pieces without visually joining them. The result gives the parser the category boundary directly: packageName$member cannot be mistaken for a field chain or a method call (packages.md §3.4). The cost is an unfamiliar separator where other languages reuse . or ::; Zane spends that familiarity to preserve one meaning for each delimiter and to keep the namespace crossing visible.
State has to be a value
A namespace and compilation unit can easily turn into a singleton object by accident. Permit mutable variables at package scope and any function in the package can read or change time-varying state without receiving it. For Zane that is not merely the usual objection to globals. It would destroy the effect model: a call whose visible inputs contain no mutable receiver or state-bearing parameter could still mutate hidden storage, so the signature would stop carrying the information effect inference relies on.
We therefore did not try to make package mutation safer with initialization-order rules, synchronization, or a special global effect. Those approaches preserve the hidden channel and then build machinery around it. The simpler answer is that mutable state is a value. Put it in a struct or reference-typed object and pass or store that value through the ordinary ownership, receiver, and capability mechanisms. Packages may still expose immutable constants and verbs, but no time-varying package slot exists (packages.md §5).
This rule makes some programs more explicit than a global-state design would. A shared service, cache, or registry needs an object, and code that uses it must receive a path to that object instead of reaching through a package name. That wiring is not accidental ceremony; it is the evidence that lets the effect model see where mutation can happen. Packages organize declarations. Values carry state.
What an import writes is what the file writes
The barrier that joins the name settled that an imported member stays qualified, and gave a good reason: every cross-package reference shows the reader its origin, without an import list to consult or a collision to resolve. That reason has not weakened. What changed is that a second pressure arrived which the rule could not accommodate.
core became an ordinary package (its own story explains why), and core is the package whose members appear in every line of every file. Under one mandatory spelling, core$Int would have been written more often than any other token in the language. The rule was not wrong; it was calibrated for a package you reach for occasionally, and core broke that assumption by being universal.
The escape we did not take was to give core an exemption — predeclared names, or a blessed always-unqualified package. That is the carve-out the previous account of cutting core loose had already identified as the expensive part, and re-adding it under a different name would have produced one rule for reaching Int and another for reaching everything else. If the qualification rule cannot hold for the package everyone uses, the honest conclusion is that it should not have been a single rule at all.
So the import states its own spelling, and there are several (packages.md §3.3). import math keeps math$sqrt. import math$sqrt makes it bare. import math$sqrt as root renames it, import math as m renames the qualifier, import math$[sqrt, pow] takes a few, and import math$ takes everything. The organizing idea is that what appears after import is what appears at the use site — the qualifier ends wherever the import ends it — which is the same species of rule as choosing a delimiter by what it separates.
The property that keeps the original reason alive is narrower than qualification but does most of its work: each imported entity has exactly one spelling in a file (§3.4). An as rename does not add a spelling, it replaces one. import math and import math$sqrt cannot both appear, because sqrt would then be reachable two ways. A reader still cannot be looking at two spellings for one entity; what they lose is the guarantee that the name itself carries its origin, and they now recover the origin from an import list at the top of the file rather than from the call site. That is the real cost of the change and it is not small — it is exactly what the older chapter was protecting.
The rest fell out of rules already in place, which is usually the sign that a shape is right. Importing a single overload of a verb is not expressible, because an overloaded name is a set that only a call site collapses, so a member import takes the whole set or nothing. Colliding bare names are legal precisely when they form a valid overload set — verbs differing in parameter types — and are otherwise an error at the import declaration rather than at the use site, so the conflict is reported where the imports are listed. An as alias keeps the initial case of what it renames, because case is semantic. And an import reaches plain-name resolution only: it contributes no operator candidates, changes no method lookup, and alters no implicit-constructor visibility, each of which is settled by a home package rather than by a file’s imports. Methods and operators are therefore not importable at all — not a restriction added for this feature, just the observation that neither was ever reached by a plain name.
It is worth being clear that none of this is a linkage mechanism. An import is a spelling and nothing else: every name resolves to its fully qualified declaration before anything downstream sees it, and the package name a compiled symbol carries is the defining package’s own, whatever alias the importing file gave it.
The manifest names the package
The first chapter named a package after its directory, and nothing contradicted that until we wrote down what a project looks like on disk. The dependency design had long since put a project’s source in a src/ directory beside its manifest (dependencies.md §3), and the moment a tool had to create one, the two rules met: the directory holding every project’s source is called src, so every package in the language was named src. Each file would open with package src, and every exported symbol would carry src where its name should be. The hash in the symbol would still have kept two libraries apart at link time, but the name after it is there for the person reading a symbol dump, and src tells that person nothing.
The basename rule had to go, and three sources could take its place. The first was the project’s own directory, which holds src/ and the manifest. It needs no new field, and for a fresh checkout it usually gives the right answer. But a filesystem operation can change a directory name. Cloning a repository under another name, or renaming the checkout, would rename the package, and the declaration in every file would then fail. That is the move the first chapter built the declaration to catch, now firing on an operation that should not matter. The second was the last part of the repository URL, which follows from the package’s identity. A project being written has no URL yet, though, and the name would still be borrowed from a host’s naming rules rather than chosen. The third was a name field in zane.coda, written once when the project is created (packages.md §2.1). We took the field. It is the only source of the three that the author states rather than inherits from the environment.
The declaration check survived unchanged in purpose. Every file still repeats the package name (packages.md §2.2), and a file copied in from another project still fails loudly, because what it repeats is now the manifest’s name. Membership still comes from the directory: a package is the files directly in its project’s src/ directory.
That raised the question of a subdirectory of src/, and we had not designed one. One plausible answer is that each subdirectory is a project of its own, versioned on its own and joined to its parent by a local path dependency. We did not commit to that. A .zn file in a subdirectory is a compile-time error for now, which keeps the space free for whatever the design turns out to be rather than giving it a meaning we would later have to take back.
The costs are small but real. A package’s name can now differ from every name a person sees on disk: a library whose manifest names it math still compiles as math when it is cloned into a directory called geometry-old, and only the manifest records that name. Renaming a package means editing the manifest and the first line of every file, which is the same number of edits as renaming the directory used to take, but the two places are now of different kinds. And a project gets one package until the subdirectory question is answered, so a larger codebase has to be split into separate projects to have more than one.
A library’s tests live in test/ and import it as a consumer
A library could not be run. zane run refuses one, because there is nothing in a library for a user to start, and that left its author two ways to try the code they had just written, neither of them good. The first was to give the library a main of its own, which the chapter on kind had kept legal for exactly this. But a library built on its own was the root of that build (packages.md §6.1), and the root package reaches the program’s console directly. The library was being exercised with a power that no consumer would ever hand it, so a library function that printed on its own worked under test and failed to compile in the first project that depended on it. The second way was an application project beside the library, joined to it by a local path dependency. That design tested the right code, but it cost a second manifest, a second lock file and a second compiler pin for every library, all of which had to be kept in step with the first by hand.
What we wanted was the second arrangement without the second project, and Dart already had it. A Dart package keeps its tests in test/, and each test file imports the package the way any other program would. We took that shape: a project holds a test/ directory, whose packages import the code under test and are the roots of the builds that run them (packages.md §7). The point we cared most about is that the roles come out right with no rule written for them. The test package is the root, so it reaches the console; the code under test is a dependency, so it does not, and anything it prints has to arrive as a parameter, exactly as it will in a real consumer’s build (§7.2). The earlier sentence that a library tested on its own is the root of that build is the claim this retires.
The other well-known arrangement gives tests more reach rather than less. Kotlin’s test source set is compiled into the same module as the code it tests and sees its internal members, and Go’s test files sit in the package’s own directory and see everything. Either would have let a test call a _-prefixed helper directly. We did not want it. Privacy lives in the name, and the rule is short because it has no exceptions; a test package that could see past it would make _ mean “private, except to one other package”, and every reader of the rule would have to learn the exception. Go’s layout had a second problem of its own here: test files beside the source would sit among the files a release compiles. So a test package imports what it tests like anyone else, and reaches only what anyone else reaches (§7.3).
One part of Dart’s design did not carry over. Each Dart test file has its own main and runs as a program of its own. A Zane directory is one compilation unit with no order among its files (the first chapter), so a test package is one directory with one main. We did not treat that as a loss. Discovering test functions, running each one and reporting which failed is a job for a library, and a testing library can be written in Zane like any other; the language gained a directory and a package name, and no test construct at all.
Rust suggested a split we weighed and declined. It keeps integration tests in tests/ and runnable demonstrations in examples/, and we asked whether Zane wanted both a test/ and an example/. The tooling could not tell them apart: each would be a root package importing the code under test and running a main, differing only in what that main does and whether CI runs it. Two directories would have required two fixed names and two lists of extra dependencies for one mechanism. A demonstration that deserves to stand on its own can already be a program with a path dependency, as an example in another repository would be anyway. We also considered naming the directory consumer/, which accurately describes the relation of its packages to the code they import. It describes the mechanism, though, not the job, and it read badly everywhere it would appear: zane consumer, package consumer. test is understood without explanation.
The name of a test package is fixed: every one of them declares package test. A test package is never published, so its name never reaches a symbol a reader sees in a dependency, and a fixed name saves the author a pointless choice. It cost one reservation: no library package may be named test, because a test would then import a package with its own name.
A testing library is a dependency the project’s consumers should never fetch, so the manifest needed a place for dependencies that only the test packages use. We put a test-deps block in the root zane.coda, beside deps and with the same columns, and a manifest fetched transitively has its test-deps ignored the way its from column already was (dependencies.md §2.1). The alternative was a second zane.coda inside the test/ directory. That would have made the test directory a project of its own, with its own compiler pin and lock file, and with pins for the project’s own dependencies that could drift from the pins the library builds with — the second project we had set out to avoid, moved into a subdirectory. One manifest and one lock file keep a project’s tests built against the same versions as the code they test.
The first version of all this was for libraries only, because an application could not take part. Its one package was the root of every build of the application and reached the console, and making a test package the root instead would have turned it into a dependency, which may not, so it would have stopped compiling. Asking why that was a cost, rather than accepting it, is what reopened how a project lays out its packages at all.
A project’s packages move into lib/, bin/ and test/
The application that could not be tested had one package because every project did. The manifest chapter had made a project’s source the files directly in src/, and there we had left a subdirectory of src/ an error rather than guess at its meaning. An application’s logic and its main lived in the same package, and that package reached the console, so there was nowhere to put the logic where a test could reach it as a dependency.
The first answer we reached for was a tree. src/gui/ would be a package, src/gui/opengl/ a package beneath it, and src/main.zn the top. A package would import only its direct children, never its parent or a sibling, and every name would be relative, so the files of src/gui/opengl/ would declare package opengl. A project depending on this one would see the top package alone. We liked what that forced: every layer would have one entry point, and a codebase would have to be modular to be written at all.
It broke on the first shared dependency. If opengl and vulkan both need a math package, a tree has nowhere to put it. As a child of opengl it is out of vulkan’s reach; as a sibling of both it is out of both, since siblings cannot import each other; hoisted to their common parent, it is visible to the parent and to neither of the packages that needed it. Every arrangement we tried for one shared package made it invisible to someone who needed it.
So we took OCaml’s layout instead, as dune lays it out: libraries in lib/, executables in bin/, tests in test/ (packages.md §2.1). Every directory directly in lib/ is a library package, and every library package of a project may import every other, as long as the imports form no cycle. math sits beside opengl and vulkan, and both import it. A directory of bin/ is a program package with its main, and a project may have several, one per subdirectory, which also retires a cost the chapter on kind had accepted: a library that wanted to ship a command-line tool no longer had to become two projects. test/ takes the same shape as lib/, one test package per directory. The roots partition by directory now. A program or test package is the root of its build and reaches the console; a library package never is, even in its own project’s builds, so it never reaches the console except through a parameter (§6.1).
That left two manifest fields with less to do. We meant to keep kind. It made projects uniform to reason about, and the toolchain could read a project’s category from its manifest when fetching it instead of inspecting its directories. But a project with both lib/ and bin/ is both a library and an application, and a field that must hold one or the other makes exactly that project impossible to describe. So kind went, and what it guarded is now stated about the directories: a dependency must have at least one public library package, and its programs and tests are never compiled (dependencies.md §9). The name field went too. It existed because every project’s source sat in a directory called src, which named nothing. A directory of lib/ is one the author named on purpose, so the directory names the package again, as it did before src/ arrived, and the field had nothing left to name (packages.md §2.2). The objection that had ruled the project directory out as a package name — a clone under another name would rename the package — does not reach a directory inside the project, which a clone does not rename.
A dependency now publishes several packages, so import geometry no longer names one. We considered qualifying the import by the project, as import geometry/math or import geometry.math, and giving each package its own manifest key. We took the plainest form instead: import math names the package math, wherever it comes from (dependencies.md §8). The manifest key stayed, but only as a label that commands name a dependency by. The cost is that one project cannot use two dependencies that both publish a math, and its own packages cannot share a package name with a dependency’s either; the toolchain stops with an error naming both. This is not the global uniqueness rule that the chapter on two packages called math turned down as a registry in a different coat. Names need to differ only among what one project reaches directly, and two projects deep in a graph may each have a math without meeting. A library package whose name begins with _ stays out of that space altogether: its own project imports it, and no other project can (packages.md §4.4), so an author can name an internal package freely.
The rest is what a larger layout always costs. A project that was one directory of source is now at least two levels deep, and a small library still has to put its one package in lib/ under a name of its own. The symbol a library exports now carries its package’s name rather than its project’s, so a reader of a symbol dump sees math, and only the hash identifies which project’s math it is.
Subpackages nest inside a library package
A flat lib/ is easy to read at ten packages and hard at a hundred. A large library has internal structure that a flat list hides, and the only way to show it was to spell it into names. The tree we had given up was right about structure, and wrong only about where it applied.
So a library package may hold subpackages, to any depth: lib/gui/opengl/ is a package inside gui, and only gui imports it (packages.md §2.3). A subpackage of opengl is imported by opengl alone. No other project sees a subpackage at all, and nothing outside its parent in its own project does either. What we had liked about the tree came back: a package with subpackages has one entry point, and its parts stay private by position, not by convention.
What broke the tree did not come back, because a subpackage may also import the project’s top-level library packages (§4.3). opengl and vulkan, now subpackages of gui, share math by importing it from lib/ directly. A subpackage still never imports its parent or a sibling, and never the top-level package it lies within, which would close a cycle. Names stay relative, so the files of lib/gui/opengl/ declare package opengl, and a subpackage may not take the name of a top-level library package of its project, which its parent would otherwise be unable to tell from it. A subpackage’s name cannot begin with _ either, since its position already makes it private and the prefix would add nothing.
bin/ stays flat. A program package exists to wire library packages into a program, and functionality big enough to need structure belongs in lib/, where it can be tested.
Testing reached subpackages by mirroring. Only gui may import opengl, so a test of opengl has to stand where gui stands, and test/gui/opengl/ does exactly that: it imports lib/gui/opengl/, sees what gui sees of it, and nothing below it (packages.md §7). We considered letting a test package import anything in the tree, which would have been simpler to state. It would also have been the one package exempt from the rule that only a parent reaches its subpackage, the same kind of exception we had declined to make for _ members in the first test chapter.
The symbol a subpackage exports names its path within lib/, as gui.opengl, because two parents may each hold an opengl (dependencies.md §6.1). The costs are the structure’s own. Code that two subpackages of different parents both need cannot stay where it was written; it has to move up into a top-level library package of its own. The test tree grows as deep as the library tree. And a consumer can never be handed a subpackage directly, which is the point, but means a library that wants to publish one has to make it a top-level package.
main may abort with a @primitives$String, and the program ends with a status
The test packages showed the gap. A test build runs its program, and the test runner can only distinguish pass from fail by how the program ends. The spec had never stated how a program ends. main could return a value, which the program discarded, it declared no abort type because nothing above it could handle one, and nothing in core set an exit status. A test that checked a value and printed FAIL therefore passed. The only way to fail was to stop on purpose, by indexing out of range, and then the reason never reached the output.
We looked at two other shapes before the shape we took. One was a verb on the program handle that ends the process with a chosen status, gated as a capability so only the root package could reach it. The other was a test-only fail or assert in core that stops with a non-zero status after printing its message. Both add an exit from the program that is not one of the two exits a verb already has, and that exit would cut through whatever scopes are still open. The language already has a mechanism for a verb to report that it failed and why: its abort. What main lacked was a caller for that abort, and giving it one was also the cheapest answer: it adds no new language feature, only a rule about who handles an abort that already exists.
So the program became that caller. main may declare one abort type, and an abort of main writes its message to standard error and ends the program with status 1, while a return ends it with 0 once its output is written (packages.md §6.3). Failure deep in a program now reaches the top the way every other failure does, through the aborts of each caller in turn, and it ends the program with a reason attached. Nothing new happens in the scopes it passes through.
The type of that abort was the one real choice. The program writes the message, so the type has to be a type the program knows how to write. core’s String was the natural candidate, and a type a test author already holds. But the spec cannot name a library type in a rule about the language: core is an ordinary package (packages.md §3), and a rule that named its String would tie the language to one release of one library. The string the language itself defines is @primitives$String, so that is the one abort type main may declare (packages.md §6.2). Any other is still a compile-time error, now one that names the type that is allowed.
That choice has a cost, and we found it while writing the first test. An abort is not a coercion site, for the same reason a return is not: the destination is a type the verb fixed itself (types.md §4.2). A message built from core strings therefore does not become a @primitives$String on its own, and has to be converted where the abort is written. core already declares that conversion, as an implicit constructor from its String. Calling it by name turned out not to work. A call that named a constructor had only looked in the built type’s own package and in the caller’s, and core’s conversion lives in the home of the source type, which the orphan rule allows (types.md §4.5). Nothing in the rules asked for that narrower reach, so we closed the gap rather than work around it: a call that names an implicit constructor finds it wherever a coercion site would (types.md §4.1). A failing check in main now reads abort @primitives$String("FAIL " + name);, longer than it would be if abort converted for itself.
The rest of the cost is in what the design leaves out. A program has one failure status, 1, and cannot choose another, so a tool that distinguishes kinds of failure by status code cannot be written in Zane. And code outside the root package cannot end the program at all. A library that wants to give up has to abort, and every caller up to main has to pass that abort on.
A dynamic library is a package without main
Every rule in the spec presupposed a program that starts at main and runs until main returns. A GUI library that should run as an audio plugin broke that assumption: an audio workstation loads a plugin as a dynamic library into its own process and calls into it, and no main ever runs. We could have treated the dynamic library as a compiler flag, but each question it raised changed the meaning of a Zane program: which verbs C may call, who holds an object between calls, where capabilities come from, and how a stop behaves. So the spec defines it (packages.md §8).
A dynamic library is a plugin package: a bin/ package that declares no main (packages.md §8.1). We kept it in bin/ and kept it a root, because which exports go into one file is a decision about one build. A project builds a CLAP plugin and a Python module from one app, so the choice cannot live in the app’s library. The plugin package holds export lines that name the libraries whose exports go into the file, and every zane build still has one root to start from.
What C calls is an exported lambda, a package-scope lambda followed by export "cName" (packages.md §8.2). We export lambdas and never verbs, because a lambda is the one callable that is a value, and ffi.md already hands function values to C as C function pointers. The export mirrors a foreign variable, which brings a C global in as a value. Symbols a host looks up by a fixed name, such as clap_entry, come from the library’s C glue, since some of those names are not even legal Zane identifiers.
An exported lambda is an entry point, as main is, so it has the rights of root-package code in every build (packages.md §8.4). An instance that needs a capability between calls stores it when its create export constructs it, which is ordinary constructor injection. Two rules keep the capability model intact: only a root package’s code calls an exported lambda, and a library calls none, its own included, so no library gains outside access that nobody handed it. A stop inside a dynamic library ends the host’s process, as a stop ends a program, because for a dynamic library the program is the host’s process. A crashing C plugin ends its host the same way.
The cost is a second kind of bin/ package, told apart only by whether it declares main, and one more form of entry point for a reader to recognise. We accepted it, because the alternative, a flag outside the language, would have left the meaning of every export to the build tool.
A library takes its user’s types as parameters
Plugin packages let a project build a CLAP plugin, but every plugin then needs the same protocol code: the factory and descriptor, the GUI, parameter, audio-port and state extensions, the child window and its GPU surface, and the conversion of CLAP’s buffers and events. That code differs between plugins only in which app it drives, so it belongs in one library. An ordinary library cannot hold it, because control is inverted. An ordinary library is used: its user calls it. A host-format library uses its user: the host calls the library, and the library calls the app. The library is written before the app exists, so it must be generic over the app’s types, and a host calls only concrete C functions by name, so nothing in Zane gave the compiler the concrete copy to make. C++’s JUCE solves the inversion with an undefined function the user must define and with virtual methods; Rust’s nih-plug, with a trait and a macro that generates the entry points. Zane has neither dynamic dispatch nor macros.
We let a library package take parameters, in the <> form a type’s header uses (packages.md §2.6). package clap<App Type, Dsp Type, Info Type, Params Type>; parameterizes a package as a generic type parameterizes a type: each argument list names an instance, and the compiler makes one copy per instance. A plugin package then names its app in one line, export clap<synth$Synth, synth$Dsp, synth$SynthInfo, synth$Params>;, and the instance supplies the plugin’s exports. Inside the copy every type is concrete, so every exported lambda is an ordinary concrete function, and no generic function value is needed. The library takes Dsp and Params as parameters of their own, because Zane has no associated types and the library declares fields of those types. Params came from the host rule. The GUI side and process each read the other’s object as a snapshot, and our first sketch had process read the whole app, which copies every widget list on every audio block. So each side keeps a flat Params value, the GUI side the values the user set and the audio side the values in effect, and each reads only the other’s Params.
The rules followed from the existing rules rather than being chosen. Every file declares its package, and its imports may use the parameters, so every file repeats the header. Zane has no shadowing, so a parameter’s name is package-wide, and a parameter is named for its role, such as App, rather than T. Every import writes its arguments in full, and an argument may name only concrete types and the importing package’s own parameters (packages.md §3.10), because a file’s imports are fixed before any verb introduces a parameter. Imports among a project’s libraries already form no cycle, so package a<T Type>; import a<List<T>>; is rejected as a cycle, and instantiation always ends without a depth limit. The export line stays even though an import names the same instance, because an import is a spelling, not a linkage: the export line is the one place that fixes a plugin’s C interface. And since a C name occurs once per build, a build exports at most one instance, so a plugin file provides one plugin; a plugin suite is several bin/ packages.
The host reads a plugin’s descriptor before it creates any instance, so the library cannot ask an app value for it. We first reached for an enum of plugins and a total enum map of their metadata, which pulled in enum iteration. What we settled on instead is a third parameter, Info, a type that is cheap to construct and has a descriptor method; the library calls Info():descriptor(), and method lookup finds descriptor in the type’s own package although the library never imports it. Making that call legal for every mould is what gave every mould constructors. The descriptor type itself lives in a small package without parameters, clapinfo, because the app’s package cannot import the instance that takes the app’s own type as an argument without a cycle.
We rejected two alternatives. Generic exports, each export written over App and copied for the types its uses supply, fail because a C host is not a use the compiler sees: no Zane code calls an export, and a call never takes a <> list, so nothing names synth$Synth. Each such export would also be a generic function value, which the language defers. Some declaration has to name the concrete types once, and the export line is that place. Package parameters, package clap<plugin Package>; with the library reading plugin$Synth and plugin$id, are ML’s functors, and every gain they offered has a type-parameter equivalent: several type parameters replace one package parameter, a method on a cheap Info value replaces metadata constants, and method lookup already reaches the app’s package. Their costs had no equivalent. A type argument would have had to become a package, so dsp<Float> would need a package declaring alias Sample = Float;, and a type expression could not be an argument at all. The library’s contract would have been the argument’s whole public interface. Host libraries would have competed for names, since CLAP and VST3 would both want an id, of different types. And packages would have become compile-time values, a new concept, where type parameters on packages reuse the machinery of generic types and the veiled-value rule covers them as written. Package parameters are worth revisiting if libraries appear whose parameter lists keep growing, since a bundle would then save more than its concept costs.
The cost is the length of an instance’s name. Every import of clap writes four type arguments, and a file that names its members either writes them in full or gives the instance an alias. Constraints on type parameters, still deferred, would let a library state what its arguments must provide; until then an argument that lacks a method fails where the instance is created, with the cause inside the library’s body, as any generic’s does.