61 karma · joined Mar 15, 2019 (7y ago) · 44 submissions
comment 9mo ago · link · parent
comment 9mo ago · link · parent
comment 1y ago · link · parent
The behaviors of multiple characters are orchestrated into a state machine. Imagine a theater with many characters performing a play. The behaviors of all characters are arranged as a whole in the script. When a certain message is sent, everyone will complete their performance according to the script.
4.
Troupe:multi-role finite state machine(ziggit.dev ↗)
2 points · by goless · 1y ago · 1 comment
comment 1y ago · link · parent
The correct way to use polystate is: reason about program behavior through symbols, then transform these symbols into code.
https://github.com/sdzx-1/ray-game/blob/master/How-to-proper...
9.
How to Properly Use Polystate?(github.com ↗)
1 points · by goless · 1y ago · 3 comments
comment 1y ago · link · parent
This is the state diagram combining two selects!
comment 1y ago · link · parent
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.
This is the actual code: https://github.com/sdzx-1/polystate-examples/blob/fecaffb5b7...
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.
https://github.com/sdzx-1/ray-game/blob/9646bc3c0f1c11314aaf...
How do you understand such behavior?
comment 1y ago · link · parent
If you look at the code here you'll see that the select state uses some functions from the parameter state.
https://github.com/sdzx-1/ray-game/blob/master/src/select.zi...
So you can see that the select state itself is incomplete, and the parameter state completes it.
It doesn't seem to be any of the 3 described above.
Perhaps it is reasonable to call it semantic composition.
comment 1y ago · link · parent
It has a completely type-safe finite state machine, and it does not require additional programming conventions.
It relies on a special monad: Mcbride Indexed Monad, which can model uncertainty in terms of type.
Are you using this monad here?
Here is a concrete ATM demo https://github.com/sdzx-1/typed-fsm/tree/main/examples/ATM
comment 1y ago · link · parent
Higher order finite state machines that require other states as parameters to work.
https://github.com/sdzx-1/ray-game/blob/master/src/select.zi...
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.
comment 1y ago · link · parent
1, https://github.com/sdzx-1/polystate?tab=readme-ov-file#2-imp...
This shows what composition means, and even complex nested selects are described quite precisely by type.
2, https://github.com/sdzx-1/polystate?tab=readme-ov-file#1-com...
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?
comment 1y ago · link · parent
I have two questions here:
1. How to express uncertain state in type. In my example, it is implemented by union (enum) + Witness https://github.com/sdzx-1/polystate-examples/blob/fecaffb5b7...
2. I don't seem to see the possibility of combining state machines