Skip to content

Where a message can land, as a type - #1

Open
m-bock-agent wants to merge 2 commits into
m-bock:mainfrom
m-bock-agent:where-a-message-can-land
Open

m-bock-agent wants to merge 2 commits into
m-bock:mainfrom
m-bock-agent:where-a-message-can-land

Conversation

@m-bock-agent

Copy link
Copy Markdown

Emitting a message and then asserting "we must be in state X now" is a
runtime throw for something the transition table already knows. This
computes it instead.

  • Transit.Class.Landings walks the table for one message and
    gives back the row of states it can end in. Three arrows labelled
    Asked all ending in Asking is one field; a message the table
    never mentions is the empty row.
  • Transit.Apply.mkApply turns a machines apply- a message in, the state it produced out - into one that answers with aVariantof exactly those landings, plusstuck` carrying the whole state.
  • Applying is the wrapper class, so a caller writes the
    specification and the message and nothing about RowToList or row
    arithmetic.

What a caller gets is a match whose branches are the states this
message can reach, each with its own payload, and no branch for a state
it cannot.

stuck is about where the machine ended up, not about whether an arrow
fired: a message with no arrow from the current state leaves it where it
was, and if that state happens to be one of the landings it reads as one.
The spec says so out loud.

Tests: 127/127. The landings assertions are compile-time and each is
forced by a second declaration - a constraint in a signature is not
solved until it is used, so the first four I wrote proved nothing.

- `Transit.Class.Landings` walks the table for one message and
  computes the row of states it can end in.
- `Transit.Apply.mkApply` turns a machine's apply into one that
  answers with that row, plus `stuck` for everything else.
- `Applying` is the wrapper class, so a caller's signature names the
  specification and the message and nothing about RowToList.
- The walk and `Contractable` move into the instance, so `Applying`
  is the only thing a caller's signature carries.
- The answer is `Either (Variant rowState) (Variant landings)`, not a
  variant with a `stuck` field: a machine with a state called `stuck`
  would have made that row carry the label twice.

This branch has not been deployed

No deployments
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