1. Record the state machine's status at the type level.
2. Achieve composable state machines through type composition.
Practical Effects of Polystate
1. Define the program's overall behavior through compositional declarations. This means we gain the ability to specify the program's overall behavior at the type level. This significantly improves the correctness of imperative program structures. This programming style also encourages us to redesign the program's state from the perspective of types and composition, thereby enhancing code composability.
2. Build complex state machines by composing simple states. For the first time, we can achieve semantic-level code reuse through type composition. In other words, we have found a way to express semantic-level code reuse at the type level. This approach achieves three effects simultaneously: conciseness, correctness, and safety.
3. Automatically generate state diagrams. Since the program's overall behavior is determined by declarations, polystate can automatically generate state diagrams. Users can intuitively understand the program's overall behavior through these diagrams.
I'm guessing you're not a native English speaker. Your descriptions could use some work. A few examples:
"For the first time, we can achieve semantic-level code reuse through type composition." is, to me, mostly meaningless. This almost certainly isn't the first time someone has done whatever it is you are claiming. What is *semantic-level" code reuse? Calling a library function is code reuse, and I expect that function to have the same semantics every time I call it. Why is type composition necessary to achieve this?
"Define the program's overall behavior through compositional declarations. This means we gain the ability to specify the program's overall behavior at the type level." How does the specifying behavior at the type level follow from composition? I can use composition, at the value level, just fine without types (e.g. in Javascript).
Yes, this effect can be achieved without using composite types. But if it is convenient and easy to achieve this effect through composite types, is it worth it?
I have to admit I'm not very interested in reading the code. I'm not likely to use this library so I'm more interested in a conceptual understanding than in the details that code requires.
Regarding composition, there are at least three ways to compose FSMs:
* Sequential: when one FSM finishes (reaches a final state) it transitions to the start state of another FSM.
* Parallel: two FSMs transition in parallel from the same input
* Nested: when a FSM reaches a certain state, another FSM starts responding to the input. When the second FSM reaches a final state, control returns to the original FSM.
It would help your description if you were clear about the kinds of composition your library supports. The terminology of FSMs is quite consistent and well defined, so I think you should be able to use it to describe what the library does.
The select, inside, and hover states here are all high-level states, and all require two state parameters. And these three states form a small state machine for handling mouse interactive selection.
Can I think of this way of using higher-order state machines as a kind of composition? A semantic composition.
You keep using the term "semantic composition", which does not have any meaning for me.
Take function composition, which is perhaps the best known example of composition. Let's say we have
f(x) = x + 1
g(x) = x * x
The composition (f o g) = g(f(x)) could be called a "semantic" composition because the result has the semantics of the two functions (it increments then doubles). So what does your use of the term actually mean?
In general I feel you need more precision in your description. There is standard terminology for finite state machines and for programming languages that I think you could use. Take, for example, your statement "all require two state parameters". I think these are not value level parameters, but type level parameters. This is an important difference, and you should mention it.
Going back to FSMs, there are several ways you can encode a FSM in a typed programming language. For example:
1. A FSM is a type constructor parameterized by the type of states. This means the FSM cannot transition to states that are not of the correct type, but it does not otherwise constrain transitions.
2. States themselves are type constructors parameterized by the type of states they can transition to. This adds more constraints (and requires more complex types) than the approach above.
Do you see the difference between these and hence the need for clarity and precision in descriptions?
Haha, thanks for your reply, I will improve my documentation to make the descriptions more accurate, and you may raise some issues to help this library better.
As for why semantic composition is used, the following example may be instructive:
yes_or_no(exit,a) This means confirm once before exiting
yes_or_no(yes_or_no(exit,a),a) Confirm twice before exiting
yes_or_no(yes_or_no(yes_or_no(exit,a),a),a) Confirm three times before exiting
This is very similar to the composition you describe.
If there is no name for this way of using state machines, then semantic composition seems appropriate.
Exceptionally, combining two states in a polystate may actually be combining two small state machines, and I think nested selects are sufficient to illustrate this.
Due to my submission yesterday, this diagram can no longer fully accurately express the current state machine, but it can probably be used as an approximate reference.
This sounds more like a product than a composition but I’m not sure. I think the parent is hinting to use established compcomp language. Sipser is a good read for this
It makes perfect sense if one considers the whole description and the field of computer sciences. It reads more like an overview that an explanation and I guess that's too be expected from any project in it's pre-mature stages of development. IMO it reads just fine, but it should delve deeper into the matter after the introduction.
I'm having trouble reading zig code, so I'm not sure how much overlap there is but I have done some work with mealy and moore encoded as co-algebras in haskell:
Yes, FSMs are underestimated in imperative programming. Of course this is probably because before type-safe state machines were available, manual coding was very error-prone.
I've seen them a lot in embedded programming, but I can't be sure if that observation holds in general or just for the environment in which I was working when I did embedded.
Typically it's done through source code generation or a runtime interpreter - state machine systems implementing a "DSL->source code" mechanism have been around for nearly as long as high level languages, and by taking this approach they have a lot of freedom to include compiler techniques of their choosing. If dynamism is called for then the diagram is typically kept in memory and interpreted at runtime.
Doing it through types is intellectually interesting and makes the result more integrated into the edit-compile loop instead of involving a step in the build process or a step of invoking an interpreter, but it might not change the practical state of the art.
In fact, I have introduced this in detail here. It is a kind of finite state machine programming, and everything that FSM can solve is suitable for it.
The automatic diagrams are great. Almost worth using a library like this just for that, since then you know the diagram actually reflects the implementation.
Note the README repeats a typo, twice, "ploystate" - the 1st two references to the package name. You'll def want to fix that pronto, it reduces confidence in quality of do s.
1. Record the state machine's status at the type level.
2. Achieve composable state machines through type composition.
Practical Effects of Polystate
1. Define the program's overall behavior through compositional declarations. This means we gain the ability to specify the program's overall behavior at the type level. This significantly improves the correctness of imperative program structures. This programming style also encourages us to redesign the program's state from the perspective of types and composition, thereby enhancing code composability.
2. Build complex state machines by composing simple states. For the first time, we can achieve semantic-level code reuse through type composition. In other words, we have found a way to express semantic-level code reuse at the type level. This approach achieves three effects simultaneously: conciseness, correctness, and safety.
3. Automatically generate state diagrams. Since the program's overall behavior is determined by declarations, polystate can automatically generate state diagrams. Users can intuitively understand the program's overall behavior through these diagrams.