Skip to content

09 · Data Structures

Standalone anonymous records

Without a nominal target, .{ fields } infers an anonymous record with exact field types and ordinary field access. An exact expected struct still selects contextual nominal construction. An invalid supplied target is diagnosed instead of being silently replaced by a structural type.

On this page

Without a nominal target, .{ fields } infers an anonymous record with exact field types and ordinary field access. An exact expected struct still selects contextual nominal construction. An invalid supplied target is diagnosed instead of being silently replaced by a structural type.

Complete example

Standalone anonymous records.

24-anonymous-records.zolo
Playground
// Anonymous records keep the exact type of each field.

// A nominal annotation still selects that type's ordinary constructor.

fn main() {
    let count = 3
    let summary = .{ count, total: 12 }
    let next = summary with { total: 15 }
    print(summary.count, summary.total)
    print(next.total)
    // expected: 3 12

    // expected: 15

}
main()

Rules and behavior

Records, maps and updates · Documentation

From a checkout of the repository:

zolo examples/features/06-data-structures/24-anonymous-records.zolo

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br