frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Polystate: Composable Finite State Machines

https://github.com/sdzx-1/polystate
35•goless•4h ago

Comments

goless•4h ago
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.

goless•4h 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•3h ago
It 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•3h ago
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:

https://blog.cofree.coffee/2025-03-05-chat-bots-revisited/ 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/

goless•2h ago
Thanks 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/todoL...

solomonb•59m ago
Right on, I'll take a look at your haskell code this week.
crq-yml•51m ago
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.

physix•8m ago
We developed an Entity DBMS where the entities are FSMs.

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•3h ago
reddit: https://www.reddit.com/r/Zig/comments/1lhfbjk/polystate_comp...
goless•3h ago
ziggit: https://ziggit.dev/t/polystate-composable-finite-state-machi...
chrisweekly•2h ago
Looks interesting.

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.

goless•2h ago
Fixed, thanks for your reminder!!
jasonthorsness•2h ago
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.
goless•2h ago
Yes, all my examples have state diagrams, they are automatically generated and are an effective way for me to understand the structure of the program.
tcoff91•1h ago
Looks kind of like a Zig version of XState, a typescript library that I really have enjoyed using.

Show HN: Wtmf.ai Your AI companion that understands

https://www.wtmf.ai
1•ishqdehlvi•1m ago•0 comments

Ask HN: Using AI daily but not seeing productivity gains – is it just me?

3•grandimam•8m ago•2 comments

Iran threatened attacks by sleeper cells inside U.S. if it was attacked

https://www.msnbc.com/msnbc/watch/iran-threatened-attacks-by-sleeper-cells-inside-u-s-if-it-was-attacked-242059333587
1•EvgeniyZh•12m ago•0 comments

RAG is the way about retrieval, agent, and grounding truth

https://psiace.me/posts/rag-is-the-way/
1•repsiace•23m ago•0 comments

RAG in Coding Agents: Making Smarter Programming Assistants

https://psiace.me/posts/rag-in-coding-agent/
1•repsiace•25m ago•0 comments

Another What to Watch App

https://what2watch2.vercel.app/
1•memonkey•34m ago•1 comments

Faking Relativity

https://tiffnix.com/faking-relativity
1•gsky•35m ago•0 comments

Show HN: SX – Transfer files from within SSH sessions without reconnecting

https://github.com/Memphizzz/SX
1•memphizzz•37m ago•0 comments

Dropping the First Atomic Bombs

https://www.theguardian.com/world/2025/jun/22/atomic-bomb-hiroshima-nagasaki-author-stephen-walker
1•rippeltippel•39m ago•0 comments

Are we overfitting our code to trends instead of problems?

1•fewbenefit•40m ago•1 comments

Nano-Vllm: lightweight vLLM implementation built from scratch

https://github.com/GeeeekExplorer/nano-vllm
3•simonpure•41m ago•0 comments

Are we overfitting our code to trends instead of problems?

1•fewbenefit•44m ago•0 comments

Framework for Skill Learning

4•michaelshoe•52m ago•0 comments

Openmovement – Watchmaking 2.0

https://openmovement.org/
1•pabs3•1h ago•0 comments

FedEx founder Fred Smith dies at 80

https://apnews.com/article/fred-smith-fedex-founder-died-645c93a192744e1ab8817ffb894ead01
1•keepamovin•1h ago•0 comments

Show HN: A zero-config HTML report plugin for Pytest (single file, CI-friendly)

1•nefaurio•1h ago•0 comments

Product Management: The Good, the Hard, and How to Know If It's Right for You

https://elezea.com/2025/06/product-management-the-good-the-hard-and-how-to-know-if-its-right-for-you/
3•mooreds•1h ago•0 comments

Implicit is better than explicit

https://sophiabits.com/blog/implicit-is-better-than-explicit
3•todsacerdoti•1h ago•0 comments

What I learned recording hours of teens on their phones

https://www.theguardian.com/film/2025/jun/22/lauren-greenfield-social-studies-documentary-film-adolescence-teenagers-phones
3•sandebert•1h ago•0 comments

Compressing for the Browser in Go

https://blog.kowalczyk.info/a-5hum/compressing-for-the-browser-in-go.html
2•todsacerdoti•1h ago•0 comments

I built an app to backup Live Photos from iPhone to external hard drives

2•xmasterdev•1h ago•0 comments

Unlocking Efficiency: Asus IoT Drives Smart Factory Development Through AI

https://iot.asus.com/resources/casestudies/drive-smart-factory-development-through-ai/
1•teleforce•1h ago•0 comments

Vera Rubin Scientists Reveal Telescope's First Images

https://www.nytimes.com/2025/06/23/science/vera-rubin-scientists-reveal-telescopes-first-images.html
3•donohoe•1h ago•0 comments

Converting Sourcemaps to Original JavaScript/TypeScript Sourcecode

https://yasoob.me/posts/converting-sourcemap-to-original-sourcecode/
2•yasoob•1h ago•0 comments

The Sad Case of the Youngest-Ever Alzheimer's Diagnosis

https://www.sciencealert.com/the-sad-case-of-the-worlds-youngest-ever-alzheimers-diagnosis
8•breitling•1h ago•1 comments

LeetCode for System Design

https://leetsys.dev
31•rbajp•1h ago•12 comments

Open Source AI Presentation Generator

https://github.com/AmNotAGoose/PPTX-Presentation-Generator
2•jonjlee•1h ago•0 comments

What's inside OpenAI Codex CLI: It’s simpler than I thought

https://medium.com/@dolevietthang/whats-inside-openai-codex-63a43ea94a48
2•vietthangif•1h ago•0 comments

Trump can pull the plug on the internet, and Europe can't do anything about it

https://www.politico.eu/article/donald-trump-eu-internet-europe-us-trade-war-data-cyber/
6•baobun•1h ago•2 comments

My go to tech stack for hosting Web Apps (including vibe coded variety)

https://musings-mr.net/post/my-go-to-tech-stack-for-web-apps
3•mrkiouak•1h ago•2 comments