-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HSMs? #7
Comments
These are very cool! I definitely think this feature should be in TypeState. Found some really good reference on wikipedia https://en.wikipedia.org/wiki/UML_state_machine I can definitely see how these can model more complicated behavior without the combinatorial increase in state trasiitions. I'll add the on-deck label to this issue. @tomlarkworthy Do you have any proposed api ideas? |
The deepest states I call terminal state, a state machine is always in a terminal state. Already your constructor API for building an FSM you set the init function. So the hierarchy of HSM is a bit like that. I wonder if there is a neat way of just nesting your existing FSMs? Doing it in a typesafe way is tricky. You could pass in the parent type of the FSM so things can call out FSM<States, ParentFSM extends FSM>
The problem is that the top state needs to know about all the possible states underneath. You can do some weird linked list templating but it probably becomes too confusing to be unusable. Union types? Not sure if they work with enums. The other approach is maybe just just having all terminal and non-terminal states in an enum, and manually setting the state hierarchy after construction:
It's quite possible for people to make an invalid hierarchy like that though (e.g. circular, partially overlapping), and it's a bit imperative in style. // side notes: If you use two numbers to represent a state, you can do very fast checks and walks over the state diagram. On construction, all enum values are terminal, so the Left = Right value. When you group, one state stops being a leaf state, and its interval is changed to encompass all the other states. |
Hierarchical state machines are a great improvement to FSMs, have you seen them before? Also known as UML statecharts.
The text was updated successfully, but these errors were encountered: