Skip to content

docs: correct three effects limitations that were broader than the truth - #565

Merged
godofecht merged 1 commit into
mainfrom
docs/correct-effects-limitations
Aug 19, 2026
Merged

godofecht merged 1 commit into
mainfrom
docs/correct-effects-limitations

Conversation

@godofecht

@godofecht godofecht commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

From the limitations list. Two of them are not limitations, and the third describes a failure mode the compiler no longer has. Issues filed for the ones that are real: #561, #562, #563, #564.

"Capabilities are stateless" — not true

The note said Flow has no mutable globals, so a handler "cannot accumulate state (e.g. a real collecting test-spy or a metrics counter)". Both of those work today.

A metrics counter:

let mut call_count: i32 = 0

capability CountingLogger {
    effect Log,
    function info(msg: string) -> void { call_count = call_count + 1 },
}
handler ran 3 times

A collecting spy, into a static array:

collected 3: 10 20 30

Capability methods have no self, which is true and worth saying. The real limit is the type: module statics must be a primitive, a fixed array of primitives, or ptr<T>, so a handler accumulating strings or structs has nowhere to put them. That is now what the page says, with #562 for whether the restriction should be widened.

"Dynamic capability objects fall back to zeroed defaults" — no longer

The note said the capability EffectName parameter style "type-checks and generates C syntax-cleanly" and then silently ignores the parameter, which would be the worst possible outcome. It does not do that:

✗ Undefined variable 'UnitCounter'

and under --lenient it reaches clang and fails there:

error: use of undeclared identifier 'UnitCounter'
    int32_t got = run_capability_Counter(&UnitCounter);

Still bad — a clang error about a symbol the author never wrote — but loud rather than silent. Corrected on the page, with #561 for making it a proper Flow diagnostic or implementing it.

The type-inference workaround is gone

function info(msg: string) -> void {
    let t: i32 = Clock.now()
-   let m: string = msg
-   printf("[%d] %s\n", t, m)
+   printf("[%d] %s\n", t, msg)
}

let m: string = msg existed because capability method bodies did not know their own parameter types, so a string parameter printed as a float. Fixed in #560. The example now passes the parameter straight through and still verifies.

Why this is worth a PR of its own

A stated limitation that is not real costs readers work: it pushes them to a more awkward pattern for cases the language already handles. Two of the three here would have done exactly that.

Validation

  • Effects showcase: 27 of 28 blocks verified, the last an intentional pattern illustration
  • Unit suite 1517 passed
  • check_doc_examples.py --check-ledger, check_doc_links.py clean

Two of the limitations recorded on the showcase were not limitations, and the
third described a failure mode the compiler no longer has.

Capabilities are not stateless. Capability methods have no `self`, which is
true and worth saying, but the note went further and said Flow has no mutable
globals, so a handler "cannot accumulate state (e.g. a real collecting
test-spy or a metrics counter)". Both of those work:

    let mut call_count: i32 = 0
    capability CountingLogger {
        effect Log,
        function info(msg: string) -> void { call_count = call_count + 1 },
    }
    -> handler ran 3 times

A spy collecting numbers into a static array works too. The real limit is the
type: module statics must be a primitive, a fixed array of primitives, or
ptr<T>, so a handler accumulating strings or structs has nowhere to put them.
That is now what the page says, with issue #562 for the underlying question.

Dynamic capability objects no longer fail the way the note describes. It said
the `capability EffectName` parameter style "type-checks and generates C
syntax-cleanly" and then silently falls back to zeroed defaults. It does not:
strict type checking rejects it, and under --lenient it emits C referencing an
undeclared identifier. Still bad, but loudly rather than silently, and worth
saying accurately. Issue #561.

The type-inference workaround is removed. `let m: string = msg` existed
because capability method bodies did not know their own parameter types, so a
string parameter printed as a float. Fixed in #560, so the example now passes
the parameter straight to printf and still verifies.

A stated limitation that is not real costs readers work, which is why these
are worth correcting rather than leaving.

Effects showcase: 27 of 28 blocks verified, the last one an intentional
pattern illustration. Unit 1517 passed, links clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@godofecht
godofecht merged commit d81b4c5 into main Aug 19, 2026
21 checks passed
@godofecht
godofecht deleted the docs/correct-effects-limitations branch August 19, 2026 07:17
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.

1 participant