Skip to content

[P0] Option/Result aren't constructable at runtime without a local type declaration #14

@ecto

Description

@ecto

The Errors and Types guides present Some/None/Ok/Err as built-in
constructors:

[match [Some 42]
  [Some x] x
  None     0]

In loon run (0.6), those forms fail with value is not callable
unless the user first declares the ADT at top level:

[type Option [Some a] None]

A missing map key also returns () (Unit), not None, so the
documented Option idiom doesn't even arise from get.

What to decide

Pick one canonical story and align everything to it:

  • Option A: ship Option and Result in the prelude so the docs
    work as written, and make [get m :k] return None for a miss.
  • Option B: keep the runtime as-is and rewrite every guide to show
    the [type Option …] declaration and ()-as-absence, plus a
    get-with-default pattern.

Acceptance criteria

  • A runtime test that asserts the canonical story works as documented.
  • Every code sample in web/src/pages/guide/errors.loon and
    web/src/pages/guide/types.loon runs under loon run verbatim.

Found while completing the hyperpolyglot ml column (clarkgrubb/hyperpolyglot#139).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions