frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Zippers: Making Functional "Updates" Efficient (2010)

http://www.goodmath.org/blog/2010/01/13/zippers-making-functional-updates-efficient/
40•tinyspacewizard•4h ago

Comments

sevensor•2h ago
I can see how this is useful if you’re repeatedly updating the same part of a tree. I can’t quite see how to use this approach for random edits. Seems like you’re back at recreating all the nodes back up to the root every time?
agentultra•2h ago
You’re right! For random access and edits you’ll need a different solution. Maybe some monads to encapsulate the mutations.
macmac•2h ago
Zippers are part of Clojure API (clojure.zip). They take a bit of work to get used to, but once you get it they are an amazing way of making "transactional" "changes" to immutable data structures.
thom•2h ago
I've built quite a lot of functionality on top of Clojure's version of this. For deeply nested stuff it's great, necessary even. But for shallow sequences where you're mostly doing complex logic looking back and forth, I genuinely think you're better off building some sort of parser combinator solution where you can more naturally match multiple conditions over long ranges, and alter the output as you send it out, transducer-style. You're also much more likely to end up with good performance compared to the constant recursive navigation you do with zippers.
xdavidliu•2h ago
i was messing around on hackerrank a few years ago and one of the problems involved implementing Huet's zipper tree, which I did in haskell. it was quite fun

https://github.com/xdavidliu/fun-problems/blob/main/zipper-t...

contificate•1h ago
There's a neat paper where they implement basic blocks (in a control flow graph) as zippers (https://www.cs.tufts.edu/~nr/pubs/zipcfg.pdf). The neat part is that - due to how the host language works (mutation having the cost of invoking the write barrier) - their measurements show that the zipper version is more performant than the mutable version.
clarkmoody•53m ago
I've used the zipper concept with lists for making impossible states impossible [0] in the context of Rust programs. The rich enum type in Rust creates opportunities to avoid bugs by baking small state machines into the code everywhere, like loading data in the linked example.

A concrete example is for managing the active item in a list. Instead of storing the active item as an index into the vector like this:

  struct List<T> {
    items: Vec<T>,
    active: usize,
  }
...which two the glaring impossible states. The vector can be empty, or the index can be outside the vector. Each time the active item is desired, we must check the index against the current state of the list.

Instead, we can use the zipper concept so we always have a concrete active item:

  struct List<T> {
    prev: Vec<T>,
    active: T,
    next: Vec<T>,
  }
Switching to a different active item requires some logic internal to the data structure, but accessing the active item always results in a concrete instance with no additional checks required.

[0]: https://sporto.github.io/elm-patterns/basic/impossible-state...

hombre_fatal•25m ago
What does the second List impl offer over the first one?

It's the API that makes something impossible to misuse, and they could offer the same API like List.create(x: T, xs: T[]), but the first one is simpler.

First device based on 'optical thermodynamics' can route light without switches

https://phys.org/news/2025-10-device-based-optical-thermodynamics-route.html
1•bilsbie•1m ago•0 comments

Controversial Advertising: How Brands Use Outrage for Profits

https://tenscores.com/controversial-advertising/
1•tenscores•1m ago•0 comments

Long-lived gamma ray burst could signal a new kind of cosmic catastrophe

https://www.science.org/content/article/long-lived-gamma-ray-burst-could-signal-new-kind-cosmic-c...
1•bikenaga•1m ago•0 comments

GitHub Issues

https://www.githubstatus.com/incidents/k7bhmjkblcwp
1•munksbeer•2m ago•1 comments

North American ice sheets drove dramatic sea-level rise at end of last Ice Age

https://phys.org/news/2025-10-north-american-ice-sheets-drove.html
2•bikenaga•3m ago•0 comments

OpenCode – open-source Platform for Public Administration

https://opencode.de/en
1•jantissler•5m ago•1 comments

Live Materialized Views in Turso

https://turso.tech/blog/introducing-real-time-data-with-materialized-views-in-turso
1•gwd•6m ago•0 comments

Putin admits Russia downed Azerbaijan Airlines plane in 2024 that killed 38

https://www.euronews.com/2025/10/09/putin-admits-russian-air-defences-downed-azerbaijan-airlines-...
2•N19PEDL2•9m ago•1 comments

'Google for DNA' brings order to biology's big data

https://www.nature.com/articles/d41586-025-03219-w
1•Brajeshwar•12m ago•0 comments

400 years later, astronomers understand Saturn's rings

https://bigthink.com/starts-with-a-bang/saturns-rings-explained/
1•Brajeshwar•12m ago•0 comments

Why everything you thought you knew about your immune system is wrong

https://www.newscientist.com/article/2497596-why-everything-you-thought-you-knew-about-your-immun...
2•Brajeshwar•12m ago•0 comments

Ask HN: How to find a non-technical co-founder/sales person?

2•darkhorse13•13m ago•1 comments

Show HN: Daily NBA bingo/grid in the browser (no ads)

https://www.bballbingo.com/
1•teotran•15m ago•0 comments

The Martians (Scientists)

https://en.wikipedia.org/wiki/The_Martians_(scientists)
1•thelastgallon•15m ago•0 comments

Google adds limits to 'Work from Anywhere' policy that began during Covid

https://www.cnbc.com/2025/10/08/google-adds-limits-to-work-from-anywhere-policy-that-began-in-cov...
1•rntn•16m ago•0 comments

OpenAPI and HTTP Request Tool (I built) is usually enough – no need for MCP

https://terrydjony.substack.com/p/openapi-spec-http-fetch-tool-is-usually
1•terryds•16m ago•0 comments

GitHub Actions seem to be down

5•arbol•18m ago•1 comments

LINQ and Learning to Be Declarative

https://www.nickstambaugh.dev/posts/LINQ-and-being-declarative
2•sieep•18m ago•2 comments

Gen Z faces 'job-pocalypse' as firms prioritise AI over new hires, report says

https://www.theguardian.com/money/2025/oct/09/gen-z-face-job-pocalypse-as-global-firms-prioritise...
3•n1b0m•18m ago•0 comments

Etiquette Re: Soliciting

https://gusvanhorn.blogspot.com/2025/10/etiquette-re-soliciting.html
1•speckx•20m ago•0 comments

Ask HN: Anyone using Cursor/Claude Code for non-coding workflows?

1•opuslabs•21m ago•0 comments

There is 'I am AI researcher' vibecoding psychosis in social media

https://old.reddit.com/r/LocalLLaMA/comments/1o1y286/comment/nik1nm2/
3•lackoftactics•24m ago•1 comments

New report claims mass production has begun on Valve's Steam Frame headset

https://www.tomsguide.com/computing/vr-ar/valve-steam-frame-vr-headset-nearing-release-new-report...
1•starkparker•24m ago•0 comments

Hardening SSH with Touch-Verified Hardware Keys

https://www.ubicloud.com/blog/hardening-ssh-with-touch-verified-hardware-keys
2•furkansahin•25m ago•0 comments

NFC-laboratory: NFC signal and protocol analyzer using SDR receiver

https://github.com/josevcm/nfc-laboratory
1•fanf2•26m ago•0 comments

How to make your own versions of some popular bike workshop tools

https://road.cc/content/feature/how-make-your-own-versions-some-popular-tools-316157
1•Lio•27m ago•0 comments

'War is a business': Training Sudan's child fighters to 'go and get killed'

https://www.theguardian.com/world/2025/oct/08/colombian-mercenaries-sudan-war
3•mhb•27m ago•0 comments

New HuggingFace LeRobot plugin hardware drivers

https://huggingface.co/docs/lerobot/integrate_hardware
1•ratsbane•28m ago•0 comments

Show HN: Sluqe AI voice notes turn conversations into searchable memory

1•Team_Sluqe•29m ago•0 comments

The Great Software Quality Collapse Or, How We Normalized Catastrophe

https://techtrenches.substack.com/p/the-great-software-quality-collapse
8•redbell•29m ago•0 comments