←back to thread

115 points goless | 1 comments | | HN request time: 0.205s | source
Show context
goless ◴[] No.44351818[source]
Polystate's Core Design Philosophy

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.

replies(1): >>44353937 #
noelwelsh ◴[] No.44353937[source]
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).

replies(3): >>44353989 #>>44354020 #>>44356351 #
1. TimorousBestie ◴[] No.44356351[source]
> This almost certainly isn't the first time someone has done whatever it is you are claiming.

I’ve seen category theory papers on this and related topics, but I haven’t seen code in the wild. Have you?

IME this kind of finite state machine business code (as opposed to a FSM embedded in an algorithm somewhere) is written as a one-off each time.

E.g., https://arxiv.org/abs/1808.05415 comes to mind. David I. Spivak has also done some work on composition of systems that is relevant.