Skip to content

docs: clarify that singleton variants need () to be a value (#22) - #79

Merged
Roger-luo merged 2 commits into
mainfrom
docs/singleton-variant-clarify
Jul 12, 2026
Merged

Roger-luo merged 2 commits into
mainfrom
docs/singleton-variant-clarify

Conversation

@Roger-luo

Copy link
Copy Markdown
Owner

Summary

Fixes the documentation gap behind #22. A user hit two confusing MethodErrors and the root cause is that a singleton variant name like Score.ZeroZero is the variant type (a DataType), not a value — you must call Score.ZeroZero() to get an instance of Score.Type.

The existing docs mentioned this in only one terse sentence, and repeatedly compared @data singletons to Base.@enum, which plants the wrong mental model (with @enum, the bare name is the value).

Changes

  • data/syntax.mdx (canonical reference): rewrote the Singleton Variant section with
    • a caution Aside — "A singleton name is a type, not a value" — plus a REPL check (Score.ZeroZero isa Score.Type → false vs Score.ZeroZero() → true)
    • both exact errors from Problem with types #22 reproduced as ❌ WRONG / ✅ RIGHT examples (the typed-Vector convert failure and the + dispatch failure)
    • a closing "the rule is uniform" note tying it to @match patterns and clarifying when the bare type name is what you want (reflection)
  • start/algebra-data-type.mdx: added a caution right after the "@data is like @enum" Aside — the spot where the wrong model forms
  • start/getting-started.md: short note where singletons are first introduced

Verification

  • Confirmed the actual behavior (isa Score.Type, equality of constructed singletons) by running the current package.
  • Ran npx astro build: all MDX modules compile successfully. (The unrelated data/benchmark build error is pre-existing — that page's RawCode reads ../benchmark/*.jl files only generated by the gendoc step, which build:full runs first.)
  • All cross-reference anchors (#singleton-variant, #default-pattern, /data/reflection) resolve.

Closes #22

🤖 Generated with Claude Code

A singleton variant name like `Score.ZeroZero` is the variant *type*
(a `DataType`), not an instance. Users must call `Score.ZeroZero()` to
get a value of `Score.Type`. This tripped up a user (#22) with two
confusing errors: a failed `convert` when building a typed `Vector`, and
a `no method matching +(::Type{...}, ...)` when dispatching.

The docs only mentioned this in one terse sentence and repeatedly
compared singletons to `Base.@enum`, which plants the wrong mental model
(with `@enum` the bare name *is* the value).

- data/syntax.mdx: rewrite the Singleton Variant section with a caution
  Aside, a REPL check, and both errors from #22 as WRONG/RIGHT examples
- start/algebra-data-type.mdx: add a caution next to the `@enum` analogy
- start/getting-started.md: note singletons need `()` where first introduced

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
moshi-jl Ready Ready Preview, Comment Jul 12, 2026 5:35am

@codecov

codecov Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.41%. Comparing base (c1e64b0) to head (5fde2c2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #79   +/-   ##
=======================================
  Coverage   91.41%   91.41%           
=======================================
  Files          42       42           
  Lines        1607     1607           
=======================================
  Hits         1469     1469           
  Misses        138      138           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
main 5fde2c2... main / 5fde2c2...
adt_transform/transform n=100 2.69 ± 0.15 μs 2.68 ± 0.15 μs 1 ± 0.08
adt_transform/transform n=1000 29.3 ± 0.71 μs 28.9 ± 0.61 μs 1.01 ± 0.033
linked_list/sum n=100 0.511 ± 0.01 μs 0.511 ± 0.01 μs 1 ± 0.028
linked_list/sum n=1000 5.44 ± 0.05 μs 5.4 ± 0.05 μs 1.01 ± 0.013
time_to_load 0.0795 ± 0.0012 s 0.0781 ± 0.0018 s 1.02 ± 0.028
Memory benchmarks
main 5fde2c2... main / 5fde2c2...
adt_transform/transform n=100 0.178 k allocs: 5.94 kB 0.178 k allocs: 5.94 kB 1
adt_transform/transform n=1000 1.79 k allocs: 0.0583 MB 1.79 k allocs: 0.0583 MB 1
linked_list/sum n=100 0 allocs: 0 B 0 allocs: 0 B
linked_list/sum n=1000 0 allocs: 0 B 0 allocs: 0 B
time_to_load 0.145 k allocs: 11 kB 0.145 k allocs: 11 kB 1

PR #78 moved the benchmark comparison files from `benchmark/` into
`benchmark/comparison/`, but `benchmark.mdx` still referenced the old
`../benchmark/*.jl` paths. `RawCode` reads these at build time, so the
docs build crashed with `ENOENT: ../benchmark/expronicon.jl` while
rendering the benchmark page.

Point all 7 RawCode paths at `../benchmark/comparison/`. `astro build`
now completes (22 pages, 0 errors).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Roger-luo
Roger-luo merged commit 6c0a7b8 into main Jul 12, 2026
8 checks passed
@Roger-luo
Roger-luo deleted the docs/singleton-variant-clarify branch July 12, 2026 05:39
Roger-luo added a commit that referenced this pull request Jul 12, 2026
This branch is based on main, which still points the benchmark page's
RawCode components at the old `../benchmark/*.jl` paths. PR #78 moved
those files into `../benchmark/comparison/`, so the docs build (and the
Vercel preview) crashes with `ENOENT: ../benchmark/expronicon.jl`.

Point all 7 paths at `../benchmark/comparison/`. `astro build` now
completes (22 pages, 0 errors). Same fix as #79; both converge to
identical content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Roger-luo added a commit that referenced this pull request Jul 12, 2026
…are form (#80)

* feat(data): require explicit () for singleton variants; deprecate bare form

Singleton variants were written as a bare identifier (`Quit`), which
reinforced the false expectation that `Score.ZeroZero` is a *value*. It
is not — it is the variant *type*; the value is `Score.ZeroZero()`. This
tripped up users (#22) with confusing `convert`/dispatch MethodErrors.

Julia has singleton *types* (an immutable no-field struct has one egal
instance, `Base.issingletontype` == true), but the type and its instance
are always distinct objects — there is no way to make a bare name be both
a type and its value the way a Rust enum variant is. Moshi needs the
variant name to stay a type (for dispatch/reflection/pattern matching),
so the honest fix is to make the *syntax* explicit rather than to fake a
value binding.

Changes:
- `@data` now accepts the explicit `Name()` singleton form (previously
  rejected with "missing fields") and treats it as the canonical spelling.
- The bare `Name` form still parses to a Singleton but emits a
  `Base.depwarn(...; force=true)` at macro-expansion time.
- Internal `Pattern` ADT (`Wildcard`) and all test/doc `@data` blocks
  migrated to the explicit `()` form so Moshi no longer uses its own
  deprecated syntax.
- Docs updated to teach `Name()` and explain the type-vs-value point.
- Added tests for the explicit form and the bare-form deprecation
  (guarded to skip under `--depwarn=error`, which escalates to a throw).

Non-breaking (deprecation only): bumps 0.3.9 -> 0.3.10.

Refs #22

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs: fix benchmark RawCode paths so Vercel build passes

This branch is based on main, which still points the benchmark page's
RawCode components at the old `../benchmark/*.jl` paths. PR #78 moved
those files into `../benchmark/comparison/`, so the docs build (and the
Vercel preview) crashes with `ENOENT: ../benchmark/expronicon.jl`.

Point all 7 paths at `../benchmark/comparison/`. `astro build` now
completes (22 pages, 0 errors). Same fix as #79; both converge to
identical content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: revert manual version bump; let release-please handle it

The repo uses release-please (release-type: julia), which bumps
Project.toml + CHANGELOG.md from Conventional Commits on push to main.
Manually bumping to 0.3.10 conflicts with the manifest (still 0.3.9), so
revert to 0.3.9 and let the `feat:` commit drive the bump automatically.

Also de-hardcode the version in the singleton deprecation note, since the
exact release number is chosen by release-please.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(agents): note release-please owns versioning; never hand-bump

Records the lesson from this PR: manually bumping Project.toml in a
feature PR fights release-please and, once that version is released,
causes merge conflicts against main. Documents that release-please owns
Project.toml/CHANGELOG.md/manifest and derives the bump from commit types.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 5fde2c25 Deployed Jul 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with types

1 participant