Repository navigation
Let a flow member be elided and carry a dimension - #599
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
VISION.mdhas written this since the beginning, under anignore=reason saying it is not implemented:It compiles now.
Four things stopped it, none hard once separated
A bare
name : Tmember was read as composition.plant : Motornests a child flow, soangle : Anglefailed with "Angle is not a flow in this file". It is now composition whenTnames a flow and state otherwise, which is the only other thing it can sensibly mean.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 bare0.0is dimensionless and the checker rightly refuses it.State without an initializer was an error. It starts at zero now. Requiring
= 0.0on every member made the common case noisier than the model it describes, and an elided member has nowhere to put one.type Angle = Radiandid not satisfysin. 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)/dtis 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:
error: unknown type name 'Radian'. Aliases are now emitted last of the typedefs.Verification
pytest tests/./flow test --tier2 --strictcheck_doc_examples.py --check-ledgerruff check srcEight 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.mdblocks lose theirignore=. The rest are fragments rather than programs, or need features that genuinely do not exist yet.