Decimal rounding modes form an ordinary enum Adopted November 17, 2026 · 6.0.0 · Being verified
Problem A special rounding type can look like an enum while behaving differently in patterns or map keys. Code that handles every mode can then fail unexpectedly.
Decision Rounding Mode is an ordinary enum with six variants. Write Rounding Mode. Half Even() as a value and case Half Even() as a pattern.Use ordinary enum rules for exhaustiveness, equality, display and map or set keys. Examples
Six constructor patterns exhaust RoundingMode run · runtime · Verification · not-run
example.tpz Six constructor patterns exhaust RoundingMode import std.decimal { RoundingMode } import std.io { writeLine } function describe (mode: RoundingMode ) -> string { match (mode) { case HalfEven () => "half even" case HalfUp () => "half up" case TowardZero () => "toward zero" case AwayFromZero () => "away from zero" case Down () => "down" case Up () => "up" } } for mode in ([ RoundingMode . HalfEven (), RoundingMode . HalfUp (), RoundingMode . TowardZero (), RoundingMode . AwayFromZero (), RoundingMode . Down (), RoundingMode . Up ()]) { writeLine ( describe (mode)) } Expected output Exit code 0
half even
half up
toward zero
away from zero
down
up
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout half even half up toward zero away from zero down up This exact example has not been executed.
Omitting one RoundingMode variant is not exhaustive reject · checking · Verification · not-run
example.tpz Omitting one RoundingMode variant is not exhaustive import std.decimal { RoundingMode } function describe (mode: RoundingMode ) -> string { match (mode) { case HalfEven () => "half even" case HalfUp () => "half up" case TowardZero () => "toward zero" case AwayFromZero () => "away from zero" case Down () => "down" } } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
RoundingMode values are Map keys and Set elements check · checking · Verification · not-run
example.tpz RoundingMode values are Map keys and Set elements let modes: Map < RoundingMode , int > = map { RoundingMode . HalfEven (): 1 } let selected: Set < RoundingMode > = set { RoundingMode . HalfEven (), RoundingMode . Up () } Expected output Exit code 0
Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
This exact example has not been executed.
A bare HalfEven binder collides with the enum constructor reject · checking · Verification · not-run
example.tpz A bare HalfEven binder collides with the enum constructor function describe (mode: RoundingMode ) -> int { match (mode) { case HalfEven => 1 } } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
Alternatives considered Keep a special type and add constructor patterns alone. Patterns would work while keys and other uses retained separate rules.Forbid patterns and allow only ==. An exhaustive match would be rejected, and there would be two kinds of constructors.Why Rounding modes use the same conventions as other enum variants without payloads.
Changed rules Variants without payloads →Every match is exhaustive →
An enum payload can use a union containing an enum Adopted November 7, 2026 · 6.0.0 · In progress
Problem A variant may carry one of several types, including another enum. Requiring a wrapper only when the type is written as a union adds an extra step.
Decision Permit a union containing an enum as a variant payload.
Examples
Construct and match both union payload alternatives run · runtime · Verification · not-run
example.tpz Construct and match both union payload alternatives import std.io { writeLine } enum Inner { Leaf } enum Outer { Wrapped ( Inner | int ) } function describe (value: Outer ) -> string { match (value) { case Wrapped (payload) => match (payload) { case number: int => "{number}" case _ => "leaf" } } } writeLine ( describe ( Outer . Wrapped ( Inner . Leaf ()))) writeLine ( describe ( Outer . Wrapped ( 7 ))) Expected output Exit code 0
leaf
7
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Alternatives considered Require a wrapper for such unions. Storing the same values would require an extra type declaration.Forbid unions that contain enums. Whether a type is allowed should not depend on how directly it is written.Why The declared type can be used directly in the payload.
Changed rules Variants with payloads →Enum declarations and payload types →
Enum variants can use prelude constructor names Adopted November 7, 2026 · 6.0.0 · Being verified
Problem A domain enum may naturally have a variant called None or Ok. A repeated name needs to be disambiguated by type.
Decision Allow None, Some, Ok and Err as enum variant names. The declaring nominal type identifies the variant. If a union makes the name ambiguous, narrow it with an existing type pattern. Examples
Enum variants and prelude constructors retain separate identities run · runtime · Verification · not-run
example.tpz Enum variants and prelude constructors retain separate identities import std.io { writeLine } enum Reply { None, Some( int ), Ok( string ), Err( bool ) } function describe (value: Reply ) -> string { match (value) { case None() => "enum none" case Some(number) => "enum some {number}" case Ok(text) => "enum ok {text}" case Err(flag) => if (flag) { "enum error" } else { "enum false" } } } function option (value: Option < int > ) -> string { match (value) { case None() => "option none" case Some(number) => "option some {number}" } } function result (value: Result < int , string > ) -> string { match (value) { case Ok(number) => "result ok {number}" case Err(text) => "result error {text}" } } writeLine ( describe ( Reply .None())) writeLine ( describe ( Reply .Some( 4 ))) writeLine ( describe ( Reply .Ok( "yes" ))) writeLine ( describe ( Reply .Err( true ))) writeLine ( option (None())) writeLine ( option (Some( 5 ))) writeLine ( result (Ok( 6 ))) writeLine ( result (Err( "no" ))) Expected output Exit code 0
enum none
enum some 4
enum ok yes
enum error
option none
option some 5
result ok 6
result error no
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout enum none enum some 4 enum ok yes enum error option none option some 5 result ok 6 result error no This exact example has not been executed.
Typed narrowing distinguishes an enum Ok from a Result Ok run · runtime · Verification · not-run
example.tpz Typed narrowing distinguishes an enum Ok from a Result Ok import std.io { writeLine } enum Reply { Ok( int ) } function describe (value: Reply | Result < int , string > ) -> string { match (value) { case reply: Reply => match (reply) { case Ok(number) => "reply {number}" } case result: Result < int , string > => match (result) { case Ok(number) => "result {number}" case Err(text) => text } } } let result: Result < int , string > = Ok( 8 ) writeLine ( describe ( Reply .Ok( 7 ))) writeLine ( describe (result)) Expected output Exit code 0
reply 7
result 8
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Reject a shared bare constructor head before inspecting its payload reject · checking · Verification · not-run
example.tpz Reject a shared bare constructor head before inspecting its payload enum Left { Shared ( int ) } enum Right { Shared ( int ) } function describe (value: Left | Right ) -> int { match (value) { case Shared (number) => number case _ => 0 } } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
A qualified enum None uses its declared payload run · runtime · Verification · not-run
example.tpz A qualified enum None uses its declared payload import std.io { writeLine } enum Reply { None( int ) } let reply = Reply .None( 7 ) writeLine ( match (reply) { case None(value) => "{value}" }) Expected output Exit code 0
7
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Alternatives considered Reserve prelude names inside enum declarations. An unrelated type could not use the same name for its own variant.Add qualified enum names to patterns. The existing type pattern is already the one way to narrow an ambiguous case.Why Names belong to their declaring types, and normal narrowing resolves ambiguity.
Changed rules Variant names and prelude constructors →
A structural record update writes each field once Adopted November 7, 2026 · 6.0.0 · Being verified
Problem When a field occurs twice in an update, the result can depend on order. The earlier change may silently disappear.
Decision Reject duplicate field names in the same structural record update.
Examples
A structural update cannot repeat a field reject · checking · Verification · not-run
example.tpz A structural update cannot repeat a field let point = { x: 1 } let moved = point { x: 2 , x: 3 , } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
One explicit initializer can replace a copied field run · runtime · Verification · not-run
example.tpz One explicit initializer can replace a copied field Open in Playground → import std.io record Point { x: int } let original = { x: 1 } let updated = original { x: 2 } let named = Point { x: 3 } let copied = Point { .. .named, x: 4 } io. writeLine ( "{updated.x}:{original.x}:{copied.x}:{named.x}" ) Expected output Exit code 0
2:1:4:3
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Alternatives considered Let the last value win. Reordering fields could change the result.Why Each field has one explicit update value.
Changed rules Repeated structural update fields →
A constructor requires arguments even in a value position Adopted November 18, 2026 · 6.0.0 · Being verified
Problem A constructor name used like a function value could pass checking and fail later. Different constructors could give different diagnostics for the same spelling.
Decision Use Name(arguments) in a value position. A missing argument list produces TPZ5004 during checking. Bare None produces TPZ2012 during parsing under the reserved-name rule. To pass a constructor operation as a function value, call it with arguments inside a lambda. Examples
Bare payload variant is rejected reject · checking · Verification · not-run
example.tpz Bare payload variant is rejected Open in Playground → enum Choice { Full ( int ), Empty } let make = Choice . Full Expected output Nonzero exit
Expected result Expected result Rejection during check. Nonzero exit.
The required primary-location contract is Pending.
This exact example has not been executed.
Bare empty variant is rejected reject · checking · Verification · not-run
example.tpz Bare empty variant is rejected enum Choice { Full ( int ), Empty } let value = Choice . Empty Expected output Nonzero exit
Expected result Expected result Rejection during check. Nonzero exit.
The required primary-location contract is Pending.
This exact example has not been executed.
Bare Some is rejected reject · checking · Verification · not-run
example.tpz Bare Some is rejected Expected output Nonzero exit
Expected result Expected result Rejection during check. Nonzero exit.
The required primary-location contract is Pending.
This exact example has not been executed.
Bare Ok is rejected reject · checking · Verification · not-run
example.tpz Bare Ok is rejected Expected output Nonzero exit
Expected result Expected result Rejection during check. Nonzero exit.
The required primary-location contract is Pending.
This exact example has not been executed.
Empty variant uses parentheses check · checking · Verification · not-run
example.tpz Empty variant uses parentheses Open in Playground → enum Choice { Full ( int ), Empty } let value: Choice = Choice . Empty () Expected output Exit code 0
Expected result Expected result Checking accepts the program. Exit code 0.
This exact example has not been executed.
Alternatives considered Treat payload constructors as first-class functions. The same name could be a constructor or a callable function depending on position.Keep the existing diagnostic that differs by constructor. The same mistake would get a different diagnostic per constructor, without one fix.Why Code shows when it constructs a value and when it creates a function to invoke later.
Changed rules Bare constructor references →Bare None in value position →Constructors in function values →
Self names the type that conforms to a protocol Adopted November 7, 2026 · 6.0.0 · Being verified
Problem A parameter naming the conforming type could give the same role a different name in each protocol. That role needs to be recognizable.
Decision Protocol declarations take no type parameters of their own. Write Self for the conforming type.
Examples
reject · parse · Verification · not-run
example.tpz Reject an explicit protocol receiver binder protocol Labelled < T > { function label (value: T ) -> string } record Item { name: string } impl Labelled < Item > { function label (value: Item ) -> string { value.name } } let text: string = Labelled . label ( Item { name: "Moss" }) Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during parse. Nonzero exit.
No stdout.
This exact example has not been executed.
check · checking · Verification · not-run
example.tpz Use Self for the conforming type Open in Playground → protocol Labelled { function label (value: Self ) -> string } record Item { name: string } impl Labelled < Item > { function label (value: Item ) -> string { value.name } } let text: string = Labelled . label ( Item { name: "Moss" }) Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Alternatives considered Alias the receiver with protocol P<T>. The same role would have a different name across protocols.Why The conforming type is recognizable in any protocol declaration.
Changed rules Protocol declarations use Self →
Protocol signatures use ordinary function declaration rules Adopted November 7, 2026 · 6.0.0 · In progress
Problem A protocol function could otherwise need its own syntax for parameters and defaults. With no body, there is also no expression from which to infer a return type.
Decision Use ordinary generic, variadic and default parameter rules. The first value parameter need not be Self. Write the return type when the signature has no body. Examples
Implementation binders and renamed method binders remain distinct run · runtime · Verification · not-run
example.tpz Implementation binders and renamed method binders remain distinct import std.io { writeLine } protocol Echo { function echo < U : Show > (value: Self , item: U ) -> U } record Box < T > { value: T } impl < T > Echo < Box < T >> { function echo < V : Show > (value: Box < T > , item: V ) { item } } let box: Box < int > = Box { value: 3 } writeLine ( Echo .echo < Box < int > , string > (box, "ok" )) let inferred: int = Echo . echo (box, 9 ) writeLine ( "{inferred}" ) Expected output Exit code 0
ok
9
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Protocol defaults and a variadic implementation share one call plan run · runtime · Verification · not-run
example.tpz Protocol defaults and a variadic implementation share one call plan import std.io { writeLine } protocol Sum { function sum (value: Self , start: int = 10 , .. .items: int ) -> int } record Item { offset: int } impl Sum < Item > { function sum (value: Item , start: int , .. .items: int ) { let mut total = value.offset + start for item in (items) { total = total + item } total } } let item = Item { offset: 1 } writeLine ( "{ Sum . sum (item)}" ) writeLine ( "{ Sum . sum (item, 2 , .. .[ 3 , 4 ], 5 )}" ) writeLine ( "{ Sum . sum (item, .. .[ 2 , 3 ])}" ) Expected output Exit code 0
11
15
16
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
An omitted implementation result uses the protocol result context check · checking · Verification · not-run
example.tpz An omitted implementation result uses the protocol result context protocol Choose { function choose (value: Self ) -> int | string } record Item {} impl Choose < Item > { function choose (value: Item ) { 7 } } let chosen: int | string = Choose . choose ( Item {}) Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Alternatives considered Add a protocol-specific callable syntax. The same function contract would need two grammars.Keep forbidding function signatures in protocols. Functions need one declaration rule.Why Ordinary function declarations prepare readers for protocol signatures.
Changed rules Matching the protocol signature →Protocol bodies →
Protocol implementations inherit defaults and visibility from their contracts Adopted November 7, 2026 · 6.0.0 · In progress
Problem Redeclaring a default or visibility in each implementation can change the meaning of one protocol call. Overlapping implementations also need a clear rule.
Decision Implementation methods may be generic or variadic and omit return annotations. They cannot redeclare defaults or export themselves separately. Reject overlap across the dependency graph for both manual and derived implementations. Examples Implementation binders and renamed method binders remain distinct →
Protocol defaults and a variadic implementation share one call plan →
An omitted implementation result uses the protocol result context →
Conformance visibility makes a separate method export invalid reject · checking · Verification · not-run
example.tpz Conformance visibility makes a separate method export invalid Open in Playground → protocol Labelled { function label (value: Self ) -> string } record Item {} impl Labelled < Item > { export function label (value: Item ) -> string { "item" } } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
An implementation cannot introduce its own omitted argument reject · checking · Verification · not-run
example.tpz An implementation cannot introduce its own omitted argument Open in Playground → protocol Labelled { function label (value: Self , suffix: string ) -> string } record Item {} impl Labelled < Item > { function label (value: Item , suffix: string = "!" ) -> string { suffix } } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
A conditional derive and a manual specialization share the overlap check reject · check · Verification · not-run
example.tpz A conditional derive and a manual specialization share the overlap check record Box < T > derives < T : Eq > Eq < Box < T >> { value: T } impl Eq < Box < int >> { function equals (a: Box < int > , b: Box < int > ) -> bool { a.value == b.value } } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
Alternatives considered Use separate implementation functions and a precedence rule. Callers would have to recheck defaults and visibility, and order would affect which implementation runs.Keep the current restriction on implementation methods. Defaults and visibility need one owner.Why The contract establishes call defaults and implementations remain unambiguous.
Changed rules Implementation methods use ordinary functions →One conformance across the dependency graph →
Adopted November 7, 2026 · 6.0.0 · Being verified
Problem If manual and derived conformances have different visibility, changing how one is declared could break an importing caller. A manual method also needs a defined implementation to run.
Decision Manual and derived conformances follow the same import visibility. A manual method invokes the implementation from its defining module.
Examples
A manual conformance is visible through a nominal import check · checking · Verification · not-run
example.tpz A manual conformance is visible through a nominal import import remote { Item as RemoteItem } let imported = RemoteItem { n: 1 } let same = Eq . equals (imported, imported) Expected output Exit code 0
No stdout. remote.tpz A manual conformance is visible through a nominal import export record Item { n: int } impl Eq < Item > { function equals (a: Item , b: Item ) -> bool { a.n == b.n } } Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
A derived conformance is visible through a nominal import check · checking · Verification · not-run
example.tpz A derived conformance is visible through a nominal import import remote { Item as RemoteItem } let imported = RemoteItem { n: 1 } let same = Eq . equals (imported, imported) Expected output Exit code 0
No stdout. remote.tpz A derived conformance is visible through a nominal import export record Item derives Eq { n: int } Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
An imported protocol call executes its manual method run · runtime · Verification · not-run
example.tpz An imported protocol call executes its manual method import std.io { writeLine } import remote { Item as RemoteItem } let left = RemoteItem { n: 1 } let right = RemoteItem { n: 11 } writeLine ( "{ Eq . equals (left, right)}" ) Expected output Exit code 0
true
remote.tpz An imported protocol call executes its manual method export record Item { n: int } impl Eq < Item > { function equals (a: Item , b: Item ) -> bool { a.n % 10 == b.n % 10 } } Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Alternatives considered Give the two kinds of conformance different visibility. Changing how a conformance is provided could change importing code.Why Importing code can read one visibility contract.
Changed rules Conformance across modules →
Adopted November 7, 2026 · 6.0.0 · In progress
Problem A type may need a custom JSON conversion. Users need a place to define the operations and a consistent way to decode an existing tree.
Decision Manual conformance supplies ordinary encode and decode methods. Decode a tree with JSON. decode<T>(tree). The JSON Value. decode<T>() method is removed. Examples
A manual JSON implementation supplies both conversions check · checking · Verification · not-run
example.tpz A manual JSON implementation supplies both conversions import std.json { JSONValue } record Token { text: string } impl JSON < Token > { function encode (value: Token ) -> Result < JSONValue , string > { JSON . encode (value.text) } function decode (value: JSONValue ) -> Result < Token , string > { match (value. asString ()) { case Some(text) => Ok( Token { text: text }) case None() => Err( "expected token string" ) } } } Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Text and tree conversion use the same manual JSON implementation run · runtime · Verification · not-run
example.tpz Text and tree conversion use the same manual JSON implementation import std.io { writeLine } import std.json { JSONValue , parse, parseAs, stringify } record Token { text: string } impl JSON < Token > { function encode (value: Token ) -> Result < JSONValue , string > { JSON . encode (value.text) } function decode (value: JSONValue ) -> Result < Token , string > { match (value. asString ()) { case Some(text) => Ok( Token { text: text }) case None() => Err( "expected token string" ) } } } writeLine ( match ( stringify ( Token { text: "paper" })) { case Ok(text) => text case Err(message) => message }) writeLine ( match (parseAs < Token > ( "\"paper\"" )) { case Ok(value) => value.text case Err(message) => message }) writeLine ( match (parseAs < Token > ( "17" )) { case Ok(value) => value.text case Err(message) => message }) writeLine ( match ( parse ( "\"ink\"" )) { case Ok(tree) => match ( JSON .decode < Token > (tree)) { case Ok(value) => value.text case Err(message) => message } case Err(_) => "parse failed" }) Expected output Exit code 0
"paper"
paper
expected token string
ink
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout "paper" paper expected token string ink This exact example has not been executed.
An empty JSON marker omits the required conversion methods reject · checking · Verification · not-run
example.tpz An empty JSON marker omits the required conversion methods Open in Playground → record Token { text: string } impl JSON < Token > {} Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
JSONValue decoding uses the ordinary protocol call reject · checking · Verification · not-run
example.tpz JSONValue decoding uses the ordinary protocol call import std.json { JSONValue } function read (tree: JSONValue ) -> Result < int , string > { tree.decode < int > () } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
check · checking · Verification · not-run
example.tpz Decode a JSONValue with one protocol-qualified form import std.json { JSONValue } function read (tree: JSONValue ) -> Result < int , string > { JSON .decode < int > (tree) } Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Alternatives considered Keep marker-only conformance or prohibit manual implementations. Custom and derived conversions could not share the same operation contract.Why Custom and derived conversions use the same operations, with a single entry point for decoding a tree.
Changed rules JSON conformance →
Using cleans up on normal and structured early exit Adopted November 7, 2026 · 5.21 line · Being verified
Problem A file opened in a using block needs closing when the block finishes or returns early. Callers also need to know what a fault or a second close means for that guarantee.
Decision using cleanup runs on normal and structured early exit.Cleanup during ordinary runtime faults and repeated close calls fall outside the cross-host guarantee. Examples
Acquire once, run body defers, then close run · runtime · Verification · not-run
example.tpz Acquire once, run body defers, then close import std.io let mut acquisitions = 0 let mut later: () -> string = () => "unset" function acquire () -> Result < File , string > { acquisitions += 1 io. open ( "input.txt" ) } function scenario () -> Result < int , string > { using file = ( acquire () ? ) { later = () => match (file. read ()) { case Ok(text) => text case Err(e) => e } defer { io. writeLine ( match (file. read ()) { case Ok(text) => "defer:{text}" case Err(e) => "defer:{e}" }) } io. writeLine ( "body" ) 99 } Ok( 7 ) } let ignored = scenario () io. writeLine ( "acquisitions:{acquisitions}" ) io. writeLine ( later ()) Expected output Exit code 0
body
defer:payload
acquisitions:1
file is closed
input.txt Acquire once, run body defers, then close Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout body defer:payload acquisitions:1 file is closed This exact example has not been executed.
Close on return, propagation, break, and continue run · runtime · Verification · not-run
example.tpz Close on return, propagation, break, and continue import std.io let mut later: () -> string = () => "unset" function fail () -> Result < int , string > { Err( "stop" ) } function onReturn () -> Result < int , string > { using file = (io. open ( "input.txt" ) ? ) { later = () => match (file. read ()) { case Ok(text) => text case Err(e) => e } return Ok( 7 ) } Ok( 0 ) } let ignoredonReturn = onReturn () io. writeLine ( "onReturn:{ later ()}" ) function onQuestion () -> Result < int , string > { using file = (io. open ( "input.txt" ) ? ) { later = () => match (file. read ()) { case Ok(text) => text case Err(e) => e } fail () ? } Ok( 0 ) } let ignoredonQuestion = onQuestion () io. writeLine ( "onQuestion:{ later ()}" ) function onBreak () -> Result < int , string > { let mut i = 0 while (i < 1 ) { using file = (io. open ( "input.txt" ) ? ) { later = () => match (file. read ()) { case Ok(text) => text case Err(e) => e } break } } Ok( 0 ) } let ignoredonBreak = onBreak () io. writeLine ( "onBreak:{ later ()}" ) function onContinue () -> Result < int , string > { let mut i = 0 while (i < 1 ) { using file = (io. open ( "input.txt" ) ? ) { later = () => match (file. read ()) { case Ok(text) => text case Err(e) => e } i += 1 continue } } Ok( 0 ) } let ignoredonContinue = onContinue () io. writeLine ( "onContinue:{ later ()}" ) Expected output Exit code 0
onReturn:file is closed
onQuestion:file is closed
onBreak:file is closed
onContinue:file is closed
input.txt Close on return, propagation, break, and continue Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout onReturn:file is closed onQuestion:file is closed onBreak:file is closed onContinue:file is closed This exact example has not been executed.
Evaluate the return value, then close nested resources run · runtime · Verification · not-run
example.tpz Evaluate the return value, then close nested resources import std.io let mut outerClosed: () -> bool = () => false let mut innerClosed: () -> bool = () => false function isClosed (file: File ) -> bool { match (file. read ()) { case Ok(text) => false case Err(error) => true } } function makeResult () -> Result < int , string > { io. writeLine ( "return-value" ) Ok( 7 ) } function scenario () -> Result < int , string > { using outer = (io. open ( "input.txt" ) ? ) { outerClosed = () => isClosed (outer) defer { io. writeLine ( "outer-defer:inner-closed={ innerClosed ()}" ) } using inner = (io. open ( "input.txt" ) ? ) { innerClosed = () => isClosed (inner) defer { io. writeLine ( "inner-defer" ) } return makeResult () } } Ok( 0 ) } let outcome = scenario () io. writeLine ( match (outcome) { case Ok(value) => "result:{value}" case Err(error) => "open:{error}" }) io. writeLine ( "outer-closed:{ outerClosed ()}" ) io. writeLine ( "inner-closed:{ innerClosed ()}" ) Expected output Exit code 0
return-value
inner-defer
outer-defer:inner-closed=true
result:7
outer-closed:true
inner-closed:true
input.txt Evaluate the return value, then close nested resources Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout return-value inner-defer outer-defer:inner-closed=true result:7 outer-closed:true inner-closed:true This exact example has not been executed.
The native File read result makes closing observable. The outer body defer sees the inner resource closed before the outer resource closes.
An ordinary fault skips remaining cleanup run · runtime · Verification · not-run
example.tpz An ordinary fault skips remaining cleanup import std.io function divide (divisor: int ) -> int { 42 / divisor } function scenario () -> Result < int , string > { using file = (io. open ( "input.txt" ) ? ) { defer { io. writeLine ( "cleanup-observed" ) } divide ( 0 ) } Ok( 0 ) } let result = scenario () Expected output Exit code 1
No stdout. input.txt An ordinary fault skips remaining cleanup Expected result Expected result Rejection during run. Exit code 1.
No stdout.
This exact example has not been executed.
The division fault stops execution. The remaining defer and using cleanup are skipped under the fault cleanup rule → . Standard output contains no cleanup message.
Alternatives considered Guarantee cleanup on faults and repeatable close on every host. Hosts would need to implement and commit to stronger cleanup and close contracts.Require every host to publish its own cleanup and close contract. The promise covers what the implementation keeps today, and a stronger portable contract is decided with its implementation.Why Callers know which exit paths can rely on using to close the file.
Changed rules Using acquisition and cleanup order →Explicit close and failure boundaries →
Resolved pending items Using cleanup on each exit path →
Version history Adopted November 7, 2026 · 6.0.0 · In progress
Problem A field can have custom comparison or JSON conversion. Inspecting only its structure while deriving the outer record would lose that behavior.
Decision Invoke the inner type's manual or derived conformance. Connect recursive declarations through descriptor references. A JSON value cycle returns Err. A comparison cycle produces TPZ5007. Examples
Derived equality and operators use the inner manual equality run · runtime · Verification · not-run
example.tpz Derived equality and operators use the inner manual equality import std.io { writeLine } record Token { key: int , noise: int } impl Eq < Token > { function equals (a: Token , b: Token ) -> bool { a.key == b.key } } record Box derives Eq { item: Token } let a = Box { item: Token { key: 1 , noise: 10 } } let b = Box { item: Token { key: 1 , noise: 20 } } let c = Box { item: Token { key: 2 , noise: 10 } } writeLine ( "{ Eq . equals (a, b)}" ) writeLine ( "{a == b}" ) writeLine ( "{ Eq . equals (a, c)}" ) writeLine ( "{a != c}" ) Expected output Exit code 0
true
true
false
true
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Derived ordering and operators use the inner manual ordering run · runtime · Verification · not-run
example.tpz Derived ordering and operators use the inner manual ordering import std.io { writeLine } record Rank { score: int } impl Order < Rank > { function compare (a: Rank , b: Rank ) -> int { if (a.score > b.score) { - 1 } else if (a.score < b.score) { 1 } else { 0 } } } record Box derives Order { item: Rank } let a = Box { item: Rank { score: 9 } } let b = Box { item: Rank { score: 3 } } writeLine ( "{ Order . compare (a, b)}" ) writeLine ( "{a < b}" ) writeLine ( "{ Order . compare (b, a)}" ) writeLine ( "{b > a}" ) Expected output Exit code 0
-1
true
1
true
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Derived JSON uses the nested manual codec in both directions run · runtime · Verification · not-run
example.tpz Derived JSON uses the nested manual codec in both directions import std.io { writeLine } import std.json { JSONValue , parseAs, stringify } record Token { text: string } impl JSON < Token > { function encode (value: Token ) -> Result < JSONValue , string > { JSON . encode (value.text) } function decode (value: JSONValue ) -> Result < Token , string > { match (value. asString ()) { case Some(text) => Ok( Token { text: text }) case None() => Err( "expected token string" ) } } } record Envelope derives JSON { token: Token } let text = match ( stringify ( Envelope { token: Token { text: "paper" } })) { case Ok(value) => value case Err(message) => message } writeLine (text) writeLine ( match (parseAs < Envelope > (text)) { case Ok(value) => value.token.text case Err(message) => message }) Expected output Exit code 0
{"token":"paper"}
paper
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
A finite recursive enum value encodes and decodes run · runtime · Verification · not-run
example.tpz A finite recursive enum value encodes and decodes import std.io { writeLine } import std.json { parseAs, stringify } enum Chain derives Eq , JSON { End , Next ( int , Chain ) } let original = Chain . Next ( 7 , Chain . End ()) let text = match ( stringify (original)) { case Ok(value) => value case Err(message) => message } writeLine (text) writeLine ( match (parseAs < Chain > (text)) { case Ok(value) => "{ Eq . equals (value, original)}" case Err(message) => message }) Expected output Exit code 0
{"tag":"Next","values":[7,{"tag":"End"}]}
true
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout {"tag":"Next","values":[7,{"tag":"End"}]} true This exact example has not been executed.
Inserted values keep recursive JSON finite run · runtime · Verification · not-run
example.tpz Inserted values keep recursive JSON finite import std.io { writeLine } import std.json { stringify } record Node derives JSON { children: Array < Node > } let mut children: Array < Node > = [] let root = Node { children: children } children. push (root) writeLine ( "{root.children.length}:{children.length}" ) writeLine ( match ( stringify (root)) { case Ok(value) => "Ok {value}" case Err(_) => "unexpected error" }) Expected output Exit code 0
0:1
Ok {"children":[]}
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Inserted values keep recursive comparison finite run · runtime · Verification · not-run
example.tpz Inserted values keep recursive comparison finite Open in Playground → import std.io { writeLine } record Node derives Eq { children: Array < Node > } let mut children: Array < Node > = [] let root = Node { children: children } let peer = Node { children: children } children. push (root) writeLine ( "{ Eq . equals (root, peer)}:{root.children.length}:{children.length}" ) Expected output Exit code 0
true:0:1
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Alternatives considered Inspect the nested value structurally as a special case. The same protocol could produce different results for a value used alone or inside another type.Forbid recursive declarations altogether. It is enough that the inner implementation keeps its meaning inside the outer derivation.Why A nested type retains the conformance it defines.
Changed rules Nested and recursive derivation requirements →
Newtypes derive conformances explicitly Adopted November 7, 2026 · 6.0.0 · In progress
Problem A base type can support a protocol that the new named type may or may not want. Inheriting it automatically hides the decision in the new declaration.
Decision Use an explicit derives clause on a newtype, just as for records and enums.
Examples
Derive the existing protocols for a newtype check · checking · Verification · not-run
example.tpz Derive the existing protocols for a newtype newtype Item derives Eq , Order , Show , JSON = int function jsonIdentity < T : JSON > (value: T ) -> T { value } let value = Item ( 7 ) let same: bool = Eq . equals (value, value) let order: int = Order . compare (value, Item ( 8 )) let shown: string = Show . show (value) let retained: Item = jsonIdentity (value) Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Alternatives considered Inherit all conformances from the base type. The new declaration would no longer say which protocols it provides.Keep forbidding derivation for newtypes. Every nominal type should gain conformance by the same rule.Why Nominal types all show derived capabilities the same way.
Changed rules Nested and recursive derivation requirements →Newtype derivation →
Equality, ordering, and JSON each have their own requirements Adopted November 7, 2026 · 6.0.0 · In progress
Problem A value can support equality without being ordered or JSON-encodable. Reordering declarations should also have a defined effect on comparison.
Decision Map and Set equality compare membership. Order is a composable total order. Field and variant names determine comparison order independently of declaration order.JSON follows specified conversion rules, including finite floats and Result.Examples
Map and Set equality follows membership while Map values use Eq run · runtime · Verification · not-run
example.tpz Map and Set equality follows membership while Map values use Eq import std.io { writeLine } record Token { key: int , label: string } impl Eq < Token > { function equals (a: Token , b: Token ) -> bool { a.key == b.key } } record Index derives Eq { values: Map < string , Token > , keys: Set < int > } let a = Index { values: map { "a" : Token { key: 1 , label: "first" }, "b" : Token { key: 2 , label: "second" } }, keys: set { 1 , 2 }, } let b = Index { values: map { "b" : Token { key: 2 , label: "changed" }, "a" : Token { key: 1 , label: "changed" } }, keys: set { 2 , 1 }, } let c = Index { values: map { "a" : Token { key: 9 , label: "first" }, "b" : Token { key: 2 , label: "second" } }, keys: set { 1 , 2 }, } writeLine ( "{ Eq . equals (a, b)}" ) writeLine ( "{a == b}" ) writeLine ( "{ Eq . equals (a, c)}" ) Expected output Exit code 0
true
true
false
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Reordering record fields or enum declarations does not change derived order run · runtime · Verification · not-run
example.tpz Reordering record fields or enum declarations does not change derived order import std.io { writeLine } record First derives Order { z: int , a: int } record Second derives Order { a: int , z: int } enum Forward derives Order { Zed , Alpha } enum Reordered derives Order { Alpha , Zed } writeLine ( "{ Order . compare ( First { z: 0 , a: 2 }, First { z: 100 , a: 1 })}" ) writeLine ( "{ Order . compare ( Second { z: 0 , a: 2 }, Second { z: 100 , a: 1 })}" ) writeLine ( "{ Order . compare ( Forward . Alpha (), Forward . Zed ())}" ) writeLine ( "{ Order . compare ( Reordered . Alpha (), Reordered . Zed ())}" ) Expected output Exit code 0
1
1
-1
-1
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Finite floats have one JSON number conversion and preserve negative zero run · runtime · Verification · not-run
example.tpz Finite floats have one JSON number conversion and preserve negative zero import std.io { writeLine } import std.json { parseAs, stringify } record Reading derives JSON { value: float } writeLine ( match ( stringify ( Reading { value: 1.5 })) { case Ok(text) => text case Err(message) => message }) writeLine ( match ( stringify ( - 0.0 )) { case Ok(text) => text case Err(message) => message }) writeLine ( match ( stringify ( 1000.0 )) { case Ok(text) => text case Err(message) => message }) writeLine ( match (parseAs < float > ( "-0" )) { case Ok(value) => "{( 1.0 / value) < 0.0 }" case Err(message) => message }) writeLine ( match (parseAs < float > ( "1" )) { case Ok(value) => "{value == 1.0 }" case Err(message) => message }) writeLine ( match ( stringify ( 0.0 / 0.0 )) { case Ok(_) => "unexpected value" case Err(_) => "nonfinite rejected" }) writeLine ( match (parseAs < float > ( "1e9999" )) { case Ok(_) => "unexpected value" case Err(_) => "overflow rejected" }) Expected output Exit code 0
{"value":1.5}
-0
1000
true
true
nonfinite rejected
overflow rejected
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout {"value":1.5} -0 1000 true true nonfinite rejected overflow rejected This exact example has not been executed.
Result data uses the same tagged representation as enum data run · runtime · Verification · not-run
example.tpz Result data uses the same tagged representation as enum data import std.io { writeLine } import std.json { parseAs, stringify } record Outcome derives JSON { value: Result < int , string > } let value = Outcome { value: Err( "paper" ) } let text = match ( stringify (value)) { case Ok(encoded) => encoded case Err(message) => message } writeLine (text) writeLine ( match (parseAs < Outcome > (text)) { case Ok(decoded) => match (decoded.value) { case Ok(number) => "{number}" case Err(message) => message } case Err(message) => message }) Expected output Exit code 0
{"value":{"tag":"Err","values":["paper"]}}
paper
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout {"value":{"tag":"Err","values":["paper"]}} paper This exact example has not been executed.
Map membership has no implicit total ordering reject · checking · Verification · not-run
example.tpz Map membership has no implicit total ordering Open in Playground → record Lookup derives Order { values: Map < string , int > } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
A Set needs an explicitly chosen JSON representation reject · checking · Verification · not-run
example.tpz A Set needs an explicitly chosen JSON representation Open in Playground → record Membership derives JSON { values: Set < int > } Expected output Nonzero exit
No stdout. Expected result Expected result Rejection during check. Nonzero exit.
No stdout.
This exact example has not been executed.
Alternatives considered Use a fixed allowlist or admit every type. A fixed list does not express the different requirements, while unconditional admission would include types that cannot satisfy the operation.Why The meaning of each operation tells you whether a type supports it.
Changed rules Field capability domains for derivation →
Protocols follow ordinary module name rules Adopted November 7, 2026 · 6.0.0 · Being verified
Problem A protocol can move to another file, and two modules can define protocols with the same name. The spelling a caller uses need not be the protocol’s identity.
Decision Apply the regular export, import, and name resolution rules to protocols. The defining module and declaration identify a protocol through aliases and distinguish it from same-named protocols. Examples
A selected protocol alias preserves a public conformance run · runtime · Verification · not-run
example.tpz A selected protocol alias preserves a public conformance import std.io { writeLine } import contracts { Labelled as Described } import item { Item } function describe < T : Described > (value: T ) -> string { Described . label (value) } writeLine ( describe ( Item { text: "selected" })) Expected output Exit code 0
selected
contracts.tpz A selected protocol alias preserves a public conformance export protocol Labelled { function label (value: Self ) -> string } item.tpz A selected protocol alias preserves a public conformance import contracts { Labelled } export record Item { text: string } impl Labelled < Item > { function label (value: Item ) -> string { value.text } } Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
A namespace-qualified protocol resolves in bounds, impl heads, and calls run · runtime · Verification · not-run
example.tpz A namespace-qualified protocol resolves in bounds, impl heads, and calls import std.io { writeLine } import contracts as api import item { Item } function describe < T : api. Labelled > (value: T ) -> string { api. Labelled . label (value) } writeLine ( describe ( Item { text: "qualified" })) Expected output Exit code 0
qualified
contracts.tpz A namespace-qualified protocol resolves in bounds, impl heads, and calls export protocol Labelled { function label (value: Self ) -> string } item.tpz A namespace-qualified protocol resolves in bounds, impl heads, and calls import contracts as api export record Item { text: string } impl api. Labelled < Item > { function label (value: Item ) -> string { value.text } } Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Equal protocol spellings in different modules keep different conformances run · runtime · Verification · not-run
example.tpz Equal protocol spellings in different modules keep different conformances import std.io { writeLine } import first { Marked as First } import second { Marked as Second } import value { Item } function printBoth < T : First + Second > (value: T ) -> () { writeLine ( First . mark (value)) writeLine ( Second . mark (value)) } printBoth ( Item { text: "value" }) Expected output Exit code 0
first value
second value
value.tpz Equal protocol spellings in different modules keep different conformances export record Item { text: string } first.tpz Equal protocol spellings in different modules keep different conformances import value { Item } export protocol Marked { function mark (value: Self ) -> string } impl Marked < Item > { function mark (value: Item ) -> string { "first {value.text}" } } second.tpz Equal protocol spellings in different modules keep different conformances import value { Item } export protocol Marked { function mark (value: Self ) -> string } impl Marked < Item > { function mark (value: Item ) -> string { "second {value.text}" } } Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Alternatives considered Keep protocols module-local or give them global names. Either choice would need separate rules or give up the name isolation provided by modules.Why Code can span modules without changing the meaning of its public protocol contracts.
Changed rules Conformance follows nominal origin across imports →
Adopted November 7, 2026 · 6.0.0 · In progress
Problem Separate syntax for function and implementation bounds would make developers relearn the same constraint. Conditional derivation can use the same form.
Decision Put bounds in the leading parameter list, as in impl<T: Eq> Eq<Box<T>>. Write conditional derivation as derives<T: Eq> Eq<Box<T>>. Examples
check · checking · Verification · not-run
example.tpz Implement equality for a generic wrapper record Box < T > { value: T } impl < T : Eq > Eq < Box < T >> { function equals (a: Box < T > , b: Box < T > ) -> bool { Eq . equals (a.value, b.value) } } let left: Box < int > = Box { value: 3 } let right: Box < int > = Box { value: 3 } let same: bool = Eq . equals (left, right) Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Derive equality under an element bound check · checking · Verification · not-run
example.tpz Derive equality under an element bound record Box < T > derives < T : Eq > Eq < Box < T >> { value: T } let left: Box < int > = Box { value: 3 } let right: Box < int > = Box { value: 3 } let same: bool = Eq . equals (left, right) Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Use the conditional derive binder on a newtype check · checking · Verification · not-run
example.tpz Use the conditional derive binder on a newtype newtype Box < T > derives < T : Eq > Eq < Box < T >> = T let left: Box < int > = Box ( 3 ) let right: Box < int > = Box ( 3 ) let same: bool = Eq . equals (left, right) Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Alternatives considered Add a special trailing where clause. The same bound would use different syntax in functions and implementations.Why Protocol requirements are visible in the same place in both declarations.
Changed rules Generic binders and conditional conformance →
Resolved pending items Generic implementation syntax →
Version history Adopted November 7, 2026 · 6.0.0 · In progress · Version 3
Problem A generic type without conformance may need separate functions for equality or display. That creates a second way to express an existing operation.
Decision A protocol implementation can declare explicit generic parameters and bounds, and it can be conditional or conditionally derived. Write forms such as impl<T: Eq> Eq<Box<T>> and derives<T: Eq> Eq<Box<T>>. Examples Implement equality for a generic wrapper →
Derive equality under an element bound →
Alternatives considered Retain the restriction on generic conformance. Generic types would still define the same equality or display operations outside the protocol.Why Functions and implementations share one syntax for bounds, and generic types can use existing protocol operations.
Changed rules Generic binders and conditional conformance →
Resolved pending items Generic implementations and conditional derivation →Generic implementation syntax →
Version history Collections receive expected types from context Adopted November 7, 2026 · 6.0.0 · Being verified
Problem An empty array has no value that can identify its element type. Context can also supply the result type for a set or map.
Decision Propagate expected types consistently to arrays, sets, maps and comprehensions.
Examples
Array comprehension with an expected literal type check · checking · Verification · not-run
example.tpz Array comprehension with an expected literal type let array: Array < 1 > = [ for item in ([ 0 ]) => 1 ] Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Set comprehension with an expected literal type check · checking · Verification · not-run
example.tpz Set comprehension with an expected literal type let keys: Set < 1 > = set { for item in ([ 0 ]) => 1 } Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Map comprehension with an expected literal type check · checking · Verification · not-run
example.tpz Map comprehension with an expected literal type let table: Map < 1 , "one" > = map { for item in ([ 0 ]) => 1 : "one" } Expected output Exit code 0
No stdout. Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
No stdout.
This exact example has not been executed.
Give empty collections a contextual type check · checking · Verification · not-run
example.tpz Give empty collections a contextual type Open in Playground → let values: Array < int > = [] let names: Set < string > = set {} let counts: Map < string , int > = map {} Expected output Exit code 0
example.tpz: types-ok (1 module)
example.tpz: resolve-ok (1 module)
Expected result Expected result Checking accepts the program. Exit code 0.
No stderr.
Expected stdout example.tpz: types-ok (1 module) example.tpz: resolve-ok (1 module) This exact example has not been executed.
Alternatives considered Propagate context only to arrays. Changing collection kind would change the inference rule.Infer every collection's element type independently of context. One inference rule should apply to every collection kind, and this option ignores context that is there.Why The way developers state the result type works across collection kinds.
Changed rules Context for empty collections →Array comprehension type →Set comprehension type →Map comprehension type →
Callbacks chain transformations and comprehensions build collections Adopted November 7, 2026 · 6.0.0 · Being verified
Problem The same array can come from chaining existing functions or joining and filtering several sources. The two programs have different structure.
Decision Keep callback methods such as arr. map(f) for chained transformations. Use comprehensions to combine and filter sources when building a collection. Where the two forms give the same result, the specification also states when and in which order each form evaluates. Examples
run · runtime · Verification · not-run
example.tpz Reuse functions through callback methods Open in Playground → import std.io function addPadding (width: int ) -> int { width + 2 } function double (width: int ) -> int { width * 2 } let widths = [ 10 , 20 ] let chained = widths. map (addPadding). map (double) let constructed = [ for width in (widths) => double ( addPadding (width))] for width in (chained) { io. writeLine ( "callback {width}" ) } for width in (constructed) { io. writeLine ( "comprehension {width}" ) } Expected output Exit code 0
callback 24
callback 44
comprehension 24
comprehension 44
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout callback 24 callback 44 comprehension 24 comprehension 44 This exact example has not been executed.
Construct a collection from filtered sources run · runtime · Verification · not-run
example.tpz Construct a collection from filtered sources Open in Playground → import std.io let widths = [ 10 , 20 ] let paddings = [ 1 , 2 ] let outerWidths = [ for width in (widths) if (width > 10 ) for padding in (paddings) => width + padding * 2 ] for width in (outerWidths) { io. writeLine ( "{width}" ) } Expected output Exit code 0
22
24
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Observe complete callback passes and per-element comprehension work run · runtime · Verification · not-run
example.tpz Observe complete callback passes and per-element comprehension work Open in Playground → import std.io function source () -> Array < int > { io. writeLine ( "source" ) [ 1 , 2 , 3 ] } function selected (value: int ) -> bool { io. writeLine ( "select {value}" ) value > 1 } function convert (value: int ) -> int { io. writeLine ( "convert {value}" ) value * 10 } function predicate () -> ( int ) -> bool { io. writeLine ( "predicate" ) selected } function transformation () -> ( int ) -> int { io. writeLine ( "transformation" ) convert } io. writeLine ( "callback chain" ) let chained = source (). filter ( predicate ()). map ( transformation ()) io. writeLine ( "comprehension" ) let constructed = [ for value in ( source ()) if ( selected (value)) => convert (value)] io. writeLine ( "results" ) for value in (chained) { io. writeLine ( "callback {value}" ) } for value in (constructed) { io. writeLine ( "comprehension {value}" ) } Expected output Exit code 0
callback chain
source
predicate
select 1
select 2
select 3
transformation
convert 2
convert 3
comprehension
source
select 1
select 2
convert 2
select 3
convert 3
results
callback 20
callback 30
comprehension 20
comprehension 30
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout callback chain source predicate select 1 select 2 select 3 transformation convert 2 convert 3 comprehension source select 1 select 2 convert 2 select 3 convert 3 results callback 20 callback 30 comprehension 20 comprehension 30 This exact example has not been executed.
Alternatives considered Keep only one form. Code would lose a direct way to express one of those intents even when the results match.Why Readers can distinguish a function chain from collection construction.
Changed rules Callback methods and comprehensions →
Arrays, sets and ranges share callback methods Adopted November 14, 2026 · 6.0.0 · Being verified
Problem An array transformation may also be useful on a set or range. Changing the receiver need not require rewriting it as a loop.
Decision Provide eager map, filter and reduce for arrays, sets and ranges. map and filter return arrays in iteration order. reduce returns the accumulator.Examples
Transform sets and ranges with callback methods run · runtime · Verification · not-run
example.tpz Transform sets and ranges with callback methods Open in Playground → import std.io let marks = set { 3 , 1 , 2 } let doubled: Array < int > = marks. map ((value: int ) => value * 2 ) let evens: Array < int > = ( 1 .. 6 ). filter ((value: int ) => value % 2 == 0 ) let total = ( 1 .. 4 ). reduce ( 0 , (sum: int , value: int ) => sum + value) for value in (doubled) { io. writeLine ( "set {value}" ) } for value in (evens) { io. writeLine ( "range {value}" ) } io. writeLine ( "total {total}" ) Expected output Exit code 0
set 6
set 2
set 4
range 2
range 4
range 6
total 10
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout set 6 set 2 set 4 range 2 range 4 range 6 total 10 This exact example has not been executed.
Reuse functions through callback methods →
Alternatives considered Offer callback methods on arrays alone. Transformations would need different rules across types that already support iteration.Why The same transformation chain works across receivers.
Changed rules Callback methods and comprehensions →
Maps and sets preserve insertion order Adopted November 9, 2026 · 6.0.0 · Being verified
Problem Replacing a key or deleting one item need not reshuffle enumeration. Equality asks a different question from iteration order.
Decision Map keys, values, entries, iteration and display follow insertion order. Replacing a value keeps its key in place. Deleting from a map or set preserves the relative order of the remaining items. Equality ignores order. JSON object key ordering has its own rule. Examples
Keep a Map key in place when replacing its value run · runtime · Verification · not-run
example.tpz Keep a Map key in place when replacing its value Open in Playground → import std.io { writeLine } let mut values = map { "first" : 1 , "middle" : 2 , "last" : 3 } values. insert ( "middle" , 20 ) for key in (values.keys) { writeLine (key) } for value in (values.values) { writeLine ( "{value}" ) } for entry in (values.entries) { writeLine ( "{entry.key}={entry.value}" ) } writeLine ( "{values}" ) Expected output Exit code 0
first
middle
last
1
20
3
first=1
middle=20
last=3
Map{first: 1, middle: 20, last: 3}
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout first middle last 1 20 3 first=1 middle=20 last=3 Map{first: 1, middle: 20, last: 3} This exact example has not been executed.
Keep surviving Map entries in order after removal run · runtime · Verification · not-run
example.tpz Keep surviving Map entries in order after removal Open in Playground → import std.io { writeLine } let mut values = map { "first" : 1 , "removed" : 2 , "third" : 3 , "last" : 4 } values. remove ( "removed" ) for entry in (values.entries) { writeLine ( "{entry.key}={entry.value}" ) } writeLine ( "{values}" ) Expected output Exit code 0
first=1
third=3
last=4
Map{first: 1, third: 3, last: 4}
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout first=1 third=3 last=4 Map{first: 1, third: 3, last: 4} This exact example has not been executed.
Keep surviving Set elements in order after removal run · runtime · Verification · not-run
example.tpz Keep surviving Set elements in order after removal Open in Playground → import std.io { writeLine } let mut values = set { 3 , 1 , 4 , 2 } values. add ( 1 ) values. remove ( 1 ) for value in (values) { writeLine ( "{value}" ) } writeLine ( "{values}" ) Expected output Exit code 0
3
4
2
Set{3, 4, 2}
Expected result Expected result Execution completes. Exit code 0.
No stderr.
Expected stdout This exact example has not been executed.
Alternatives considered Fill a deleted slot with the last item. Deleting one entry would change the order of entries the caller kept.Leave the order unspecified. Results would not repeat.Use sorted order. Insertion order matches Set and the current behavior, so examples do not change.Why Insertion and deletion have predictable effects on iteration and display.
Changed rules Map and Set insertion order →Set order and duplicate elements →