Skip to content

Standard prelude for Result, Option, and common ADT constructors #289

@aallan

Description

@aallan

Every Vera program that uses Result, Option, or UrlParts must locally redefine the ADT to access its constructors for pattern matching:

private data Result<T, E> { Ok(T), Err(E) }
private data Option<T> { None, Some(T) }

This is 2–6 lines of identical boilerplate in every program. All 9 examples that use these types include these definitions. The v0.0.88 viability assessment flags this as boilerplate that agents "will almost certainly forget" — the type checker registers the built-in constructors (environment.py lines 145–200) but the local data declaration is still required for pattern matching.

Design tension

Goal 2 (explicitness over convenience) argues against implicit imports. But this boilerplate adds no information — every definition is identical, and omitting it produces a confusing error rather than a useful explicitness signal.

Options to consider

  1. Implicit preludeResult, Option, and their constructors are always available without declaration (like Rust's std::prelude). Simplest for agents, least explicit.
  2. Auto-import from vera.collections — the module vera/collections.vera already defines these types publicly. Making it auto-imported would provide the constructors without local redefinition.
  3. Built-in constructor resolution — extend the checker so that constructors registered via environment.py are directly usable in patterns without a local data block. The type is already registered; only the constructor names are inaccessible.
  4. Status quo with better docs — keep the redefinition requirement but improve SKILL.md templates to always include the boilerplate.

The vera.collections module already exists (examples/vera/collections.vera) and defines Option and Result publicly. A prelude that auto-imports this module would reuse existing infrastructure.

Cross-references

Metadata

Metadata

Assignees

No one assigned

    Labels

    C9C9 — Language designdesignFuture language design (spec §0.8)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions