How do I write a pure-computation publishable library in EK9?
← Package Capability Security · Ref: Q1276
For a publishable library that touches no system resources — a JSON parser, a string-manipulation utility, a collection library, a mathematical package — the idiom is simple: OMIT THE 'capabilities' BLOCK ENTIRELY.
Without a 'capabilities' declaration, the fourth publishable condition is not met, so the compiler does not activate capability enforcement for the module. The package compiles exactly as it would have before the capability feature existed. Users pulling the library can see from its package block that no 'capabilities' declaration is present and therefore the library author has not entered the capability enforcement regime — which is fine, because the library genuinely uses no gated types.
THE PURE COMPUTATION PATTERN
defines module com.example.jsonparser
defines package publicAccess <- true version <- 2.1.0-0 description <- "Pure JSON parsing library" license <- "MIT" //No 'capabilities' block: pure computation, no gated types used.
deps <- { "org.ek9.collections": "1.0.0-0" }
defines function parseJson() as pure -> input as String <- rtn as JSON: JSON() //Pure parsing logic — only String, JSON, and collection types
WHY NOT USE 'capabilities <- []'?
EK9 list literals currently require at least one element, so 'capabilities <- []' does not parse. The design intent of an empty list — 'this package is explicitly pure computation' — is achieved instead by omitting the block, which has the same practical effect: no enforcement, no gated types needed, no supply-chain risk.
WHEN TO ADD A 'capabilities' BLOCK
As soon as your library legitimately needs to touch a system resource — for example, a networking library that needs TCP, or a logging utility that needs Stdout — add the 'capabilities' block with the required entries. The moment the block exists, your module enters enforcement: every gated type in its code must be covered.
WHAT CONSUMERS SEE
A consumer who fetches a pure-computation library sees its 'defines package' block and immediately knows (a) the library is published and versioned and (b) the author has not declared any capabilities — meaning they have not opted into enforcement. A careful consumer can verify by reading the library's source that no gated types are actually used. A pure-computation library has an audit story that matches its claim.
See Q1270 for the four-condition publishable rule. See Q1271 for declaration syntax. See Q1272 for the supply chain rationale. See Q1275 for non-publishable packages (which also skip enforcement but for a different reason — they aren't published at all).
Example
defines module qa.packagecapabilities.purecomputation defines package publicAccess <- true version <- 1.0.0-0 description <- "Pure computation library — no capabilities block declared" license <- "MIT" defines function doubleValue() as pure -> input as Integer <- rtn as Integer: input * 2 concatenate() as pure -> prefix as String suffix as String <- rtn as String: `${prefix}${suffix}` isPositive() as pure -> candidate as Integer <- rtn as Boolean: candidate > 0
Other ways to ask this
- How do I publish a library that uses no system resources?
- What is the idiom for a JSON parser or maths library that doesn't need capabilities?
- Can I publish a package without declaring any capabilities?
- How do I say 'this library is pure computation' in the package block?
Coming from another language?
Maven/pom.xml: no way to declare 'this library is pure computation.' npm: no equivalent. Cargo: no equivalent. Haskell: pure functions are tracked by the type system but package-level purity is not distinguished. EK9: pure-computation publishable libraries omit the capabilities block entirely; audit is trivial because the absence of the declaration matches the absence of gated type usage.
Keywords: computation, no capabilities, parser, mathematical, library, omit, pure, JSON