frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Polystate: Composable Finite State Machines

https://github.com/sdzx-1/polystate
36•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•4h 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•3h 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•1h ago
Right on, I'll take a look at your haskell code this week.
crq-yml•1h 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.

goless•15m ago
Yes, 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•27m 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•18m ago
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.
goless•4h ago
reddit: https://www.reddit.com/r/Zig/comments/1lhfbjk/polystate_comp...
goless•4h 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.
goless•12m ago
I don't know much about XState but it looks more like a dynamically interpreted execution state machine.
astahlx•12m ago
How would you compare it to Rust Type States, for example: https://cliffle.com/blog/rust-typestate/ ?

Mechanical Watch: Exploded View

https://fellerts.no/projects/epoch.html
751•fellerts•15h ago•97 comments

Python can run Mojo now

https://koaning.io/posts/giving-mojo-a-spin/
95•cantdutchthis•2d ago•22 comments

LeetCode for System Design

https://leetsys.dev
37•rbajp•1h ago•21 comments

I wrote my PhD Thesis in Typst

https://fransskarman.com/phd_thesis_in_typst.html
239•todsacerdoti•8h ago•120 comments

Using Home Assistant, adguard home and an $8 smart outlet to avoid brain rot

https://www.romanklasen.com/blog/beating-brainrot-by-button/
179•remuskaos•9h ago•88 comments

Finding a billion factorials in 60 ms with SIMD

https://codeforces.com/blog/entry/143279
83•todsacerdoti•6h ago•5 comments

Polystate: Composable Finite State Machines

https://github.com/sdzx-1/polystate
36•goless•4h ago•19 comments

The X Window System didn't immediately have X terminals

https://utcc.utoronto.ca/~cks/space/blog/unix/XTerminalsNotImmediate
11•zdw•2h ago•2 comments

Klein Bottle Amazon Brand Hijacking (2021)

https://www.kleinbottle.com/Amazon_Brand_Hijacking.html
181•sebg•10h ago•72 comments

Tensor Manipulation Unit (TMU): Reconfigurable, Near-Memory, High-Throughput AI

https://arxiv.org/abs/2506.14364
24•transpute•4h ago•3 comments

The Tandy Corporation

https://www.abortretry.fail/p/the-tandy-corporation-part-1
13•rbanffy•2d ago•6 comments

Adobe Project Indigo is a new photo app from former Pixel camera engineers

https://www.engadget.com/apps/adobe-project-indigo-is-a-new-photo-app-from-former-pixel-camera-engineers-213453207.html
54•bookofjoe•2d ago•34 comments

Using Wave Function Collapse to solve puzzle map generation at scale

https://sublevelgames.github.io/blogs/2025-06-22-nurikabe-map-gen-with-wfc/
29•greentec•5h ago•3 comments

Git Notes: Git's coolest, most unloved­ feature (2022)

https://tylercipriani.com/blog/2022/11/19/git-notes-gits-coolest-most-unloved-feature/
495•Delgan•20h ago•116 comments

Optifye.ai (YC W25) – Founding Back End Engineer

1•Vivaan_Baid•5h ago

Hawaii Highways

http://www.hawaiihighways.com/
49•yakattak•7h ago•14 comments

Show HN: Lego Island Playable in the Browser

https://isle.pizza
44•foxtacles•7h ago•11 comments

Cross-Account and Cross-Region Backups with AWS Backup (and Friends)

https://tylerrussell.dev/2025/06/20/cross-account-and-region-backups-with-aws-backup-and-friends/
29•terussell85•2d ago•9 comments

AGI is Mathematically Impossible 2: When Entropy Returns

https://philarchive.org/archive/SCHAIM-14
104•ICBTheory•12h ago•150 comments

Radio Garden

https://radio.garden/?2025
71•LeoPanthera•8h ago•10 comments

How to negotiate your salary package

https://www.complexsystemspodcast.com/episodes/how-to-negotiate-your-salary-package/
271•surprisetalk•4d ago•228 comments

LibRedirect – Redirects popular sites to alternative privacy-friendly frontends

https://libredirect.github.io
400•riffraff•1d ago•99 comments

2048 with only 64 bits of state

https://github.com/izabera/bitwise-challenge-2048
121•todsacerdoti•3d ago•27 comments

Interview with Francine Prose on early-1970s San Francisco [audio]

https://www.laphamsquarterly.org/content/episode-3-francine-prose
51•keiferski•10h ago•7 comments

2025 Alonzo Church Award: Paul Blain Levy for Call-by-Push-Value (CBPV)

https://siglog.org/winner-of-the-2025-alonzo-church-award/
18•matt_d•1d ago•3 comments

The cultural decline of literary fiction

https://oyyy.substack.com/p/the-cultural-decline-of-literary
141•libraryofbabel•14h ago•258 comments

We’ve had a Denisovan skull since the 1930s—only nobody knew

https://arstechnica.com/science/2025/06/the-controversial-dragon-man-skull-was-a-denisovan/
75•Bluestein•3d ago•20 comments

TPU Deep Dive

https://henryhmko.github.io/posts/tpu/tpu.html
393•transpute•1d ago•80 comments

Show HN: Report idling vehicles in NYC (and get a cut of the fines) with AI

https://apps.apple.com/us/app/idle-reporter-for-nyc-dep/id6747315971
137•rafram•13h ago•178 comments

Kilauea volcano errupts, lava more than 1k feet high [video]

https://www.youtube.com/watch?v=oG5zz9Sjw3E
87•asix66•2d ago•37 comments