3 ms·
Hi everyone, I developed an interesting library Polystate: Composable Finite State Machines Since I only have experience in haskell and zig, I'm curious if the
by goless 1y ago
Hi everyone, I developed an interesting library Polystate: Composable Finite State Machines
Since I only have experience in haskell and zig, I'm curious if there are other languages or libraries with similar implementations?
- goless 1y agoIt relies heavily on compile-time evaluation of zig to achieve this, and I'm not sure if the same effect can be achieved in other languages.
- solomonb 1y agoI'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: https://blog.cofree.coffee/2025-03-05-chat-bots-revisited/ https://blog.cofree.coffee/2025-03-05-chat-bots-revisited/ https://github.com/cofree-coffee/cofree-bot https://github.com/cofree-coffee/cofree-bot Also using the lens library to encode moore machines as polynomial functors: https://blog.cofree.coffee/2024-07-02-lensy-moore/ https://blog.cofree.coffee/2024-07-02-lensy-moore/
- goless 1y agoThanks for your reply, I will try to understand your code carefully, which may take some time. I have a raw haskell prototype of polystate here, maybe it will help you. https://github.com/sdzx-1/typed-gui/blob/main/examples/todoList/README.md https://github.com/sdzx-1/typed-gui/blob/main/examples/todoL...
- solomonb 1y agoRight on, I'll take a look at your haskell code this week.
- crq-yml 1y agoTypically 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.
- goless 1y agoYes, but their expressiveness may vary. An important role of polystate is code reuse. It can express more complex states and still be type-safe.
- physix 1y agoWe developed an Entity DBMS where the entities are FSMs. https://medium.com/@paul_42036/entity-workflows-for-event-driven-architectures-4d491cf898a5 https://medium.com/@paul_42036/entity-workflows-for-event-dr... I believe that FSMs are a very powerful approach, even for building entire systems. So much so, that it forms a core part of our product.
- goless 1y agoYes, 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.
- _0ffh 1y agoI'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.
- ur-whale 1y ago> Hi everyone, I developed an interesting library Polystate A short blurb on the github explaining what applications this may have and how you would use it to solve problems would be very helpful.
- goless 1y agoIn 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.
- noelwelsh 1y agoThere are examples in Scala in the "Indexed Data" chapter of my book-in-progress: https://scalawithcats.com/dist/scala-with-cats.pdf https://scalawithcats.com/dist/scala-with-cats.pdf
- goless 1y agoI once wrote a library typed-fsm https://github.com/sdzx-1/typed-fsm https://github.com/sdzx-1/typed-fsm 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 https://github.com/sdzx-1/typed-fsm/tree/main/examples/ATM
- goless 1y agoIn fact, relying on this monad, we can achieve full type safety for multi-role communication. https://github.com/sdzx-1/typed-session https://github.com/sdzx-1/typed-session