Skip to content

Let a flow member be elided and carry a dimension - #599

Merged
godofecht merged 2 commits into
mainfrom
flow-dimensioned-state
Aug 19, 2026
Merged

godofecht merged 2 commits into
mainfrom
flow-dimensioned-state

Conversation

@godofecht

@godofecht godofecht commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

VISION.md has written this since the beginning, under an ignore= reason saying it is not implemented:

flow Pendulum {
    angle : Angle
    velocity : AngularVelocity

    angle evolves as velocity
    velocity evolves as -(gravity / length) * sin(angle)
}

It compiles now.

Four things stopped it, none hard once separated

  1. A bare name : T member was read as composition. plant : Motor nests a child flow, so angle : Angle failed with "Angle is not a flow in this file". It is now composition when T names a flow and state otherwise, which is the only other thing it can sensibly mean.

  2. A member had to be f64 or f32. A unit is already an ordinary field type — struct Pose { theta: Angle } has always compiled and stored a double. Members now accept a declared unit; the zero and the integration step carry the dimension explicitly, since a bare 0.0 is dimensionless and the checker rightly refuses it.

  3. State without an initializer was an error. It starts at zero now. Requiring = 0.0 on every member made the common case noisier than the model it describes, and an elided member has nowhere to put one.

  4. type Angle = Radian did not satisfy sin. The check compared the name instead of following the alias.

What is deliberately not done

A dimensioned rate is carried as a plain number. d(Angle)/dt is an angular velocity, and Flow cannot spell that division yet, so the state is dimension checked and the derivative is not. Naming the rate's own unit is what the north-star document describes; this is not that.

A bug this turned up

Type aliases were emitted above the units and distinct types they may name:

typedef Radian Angle;     // line 93
...
typedef double Radian;    // line 98

error: unknown type name 'Radian'. Aliases are now emitted last of the typedefs.

Verification

Check Result
pytest tests/ 1688 passed, 6 skipped
./flow test --tier2 --strict 687/687
check_doc_examples.py --check-ledger no new unverified
ruff check src clean

Eight tests in tests/unit/test_flow_dimensioned_state.py, including one that builds and runs a dimensioned pendulum and checks the arithmetic (2.0 rad/s over ten 100ms steps is 2.000), and one that a member naming neither a flow nor a unit is still an error.

Two VISION.md blocks lose their ignore=. The rest are fragments rather than programs, or need features that genuinely do not exist yet.

godofecht and others added 2 commits August 19, 2026 19:40
VISION.md has written this since the beginning, under an ignore= reason
saying it is not implemented:

    flow Pendulum {
        angle : Angle
        velocity : AngularVelocity

        angle evolves as velocity
        velocity evolves as -(gravity / length) * sin(angle)
    }

Four things stopped it compiling, and none of them was hard once separated:

- A bare `name : T` member was read as flow composition, so a type that was
  not a flow was an error. It is now composition when T names a flow and
  state otherwise, which is the only other thing it can sensibly mean.
- A flow member had to be f64 or f32. A unit is already an ordinary field
  type; `struct Pose { theta: Angle }` has always compiled. Members now
  accept a declared unit and store a number, so the zero and the integration
  step carry the dimension explicitly.
- A state without an initializer was an error. It starts at zero now:
  requiring `= 0.0` on every member made the common case noisier than the
  model it describes, and an elided member has nowhere to put one.
- `type Angle = Radian` did not satisfy the sin/cos argument check, which
  compared the name rather than following the alias.

A dimensioned rate is carried as a plain number. d(Angle)/dt is an angular
velocity, and Flow cannot spell that division yet, so the state is dimension
checked and the derivative is not.

Also fixes an emission-order bug this turned up: a type alias was emitted
above the units and distinct types it may name, so `type Angle = Radian`
produced `typedef Radian Angle;` three lines before `typedef double Radian;`.

VISION.md's pendulum now compiles, with the units in a preamble so the prose
keeps showing the model rather than the bookkeeping.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@godofecht
godofecht merged commit ba93fb8 into main Aug 19, 2026
19 checks passed
@godofecht
godofecht deleted the flow-dimensioned-state branch August 19, 2026 21:47
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