frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Losing language features: some stories about disjoint unions

https://graydon2.dreamwidth.org/318788.html
65•Bogdanp•3d ago

Comments

ivanjermakov•6h ago
I'm surprised how many modern languages lack first-class sum type support, considering the amount of domain use cases for them.
MarkusQ•6h ago
Back in the day, when memory wasn't as cheap as it is now, there was a strong belief that forcing the user to "waste bits" on a proper sum type was a non-starter for a "real" language. It was widely assumed that the reason you were "sharing memory" between two fields was to conserve space, because you were clever enough to have recognized that they couldn't both be used at the same time. But doing so, it was generally assumed, meant that you were space constrained and so anything that took away your precious savings was bad.

I'm not saying this was "right" in any sense, but it wasn't just foolish old timers not recognizing that a "better" solution was possible. When you grew up having every single bit of memory threaded by hand (and costing macroscopic amounts of money), you think about memory efficiency differently.

cbsmith•5h ago
Yeah, I remember using untagged unions because the code "knew" which type was the right one to use at the right time and you wanted to save space (and wanted your structures to fit well in registers --and later cache lines).
setr•3h ago
I suppose that’s what cobol copybooks are; untagged unions, everywhere, all the time, all at once
NooneAtAll3•50m ago
looking at VSCode and browsers eating RAM as if it's nothing makes me think modern approach isn't that good either
eru•29m ago
Maybe, but it's not sumtypes that are to blame.
jchw•5h ago
Lack of sum types is probably one of the worst things about working in Go, and I think it is a much bigger problem than the lack of generics ever was. Sadly, though, I don't think you can really just bolt sum types onto an already complete programming language design.
andrewflnr•2h ago
I wonder if a version of OCaml that had a better concurrency story 10-15 years ago could have taken Go's place.
jchw•9m ago
Maybe, but I think focusing on concurrency is the wrong idea.

I think Go + sum types could be good. Maybe. But, honestly, it's hard to say for sure. First-order effects are great: we have sum types and can use them to model problems. Second-order effects get muddy: We have sum types and they are the ideal solution for a bunch of problems, but without other features they're awkward to use. For example... now you can do a Result type... but if you want to return multiple values in a Result, you need a set/tuple type too. If you do that, is Go's multiple return values concept still a good idea? I could probably go on but hopefully this illustrates the point.

I think a lot of people don't acknowledge why Go is truly so successful. Well OK, first elephant in the room, it's obviously successful because it's backed by Google, a company who can and did throw immense resources at making the implementation and standard library pretty damn good as well as helping to push it, but that alone wouldn't have propelled it to where it is today (I mean, compare it to Dart.)

But beyond that, Go is successful because Go code is very simple to write and leaves the programmer with relatively few things to be concerned about, and yet in spite of that, Go code generally runs reasonably fast, uses relatively small amounts of memory and is generally not very crash-prone. (Some people would happily debate that, but I trust software like restic, esbuild, rclone and Syncthing every day without fail, among other smaller Go programs. I'm OK with making that assertion.)

If you put in the effort to make really good Rust code, the effort is not wasted, but it is a lot of effort when the stupid Go code often does the trick. Consider Discord's presence service: they switched from Go to Rust and massively cut costs and improved latency. Rust wins, Rust better? But... most services will never scale to the point where marginal improvements in latency, throughput or RAM are going to be worth a lot of man-hours worth of programming and ongoing maintenance. Usually throwing a couple more VMs at the problem is just going to be the path of lesser resistance. This was always the case when comparing lower-level to higher-level, but Go amplifies it because the performance gap isn't as big, but the complexity gap remains very large or maybe gets larger.

Is writing Rust code really that hard? No, not at all, it's more that writing good Go code is so relatively easy, the language is simple and the standard library is loaded with useful tools. Go's CLI flag parser is pretty unimpressive, but so many projects just need a very basic flag parser and it works totally fine for that, you just don't need to overthink it 99.99% of the time. Same for net/http, the built-in image and compression codecs, TLS stack, and more. Meanwhile, designing and maintaining good high-quality Rust crates is just relatively hard. You've got to worry about async vs sync, various cfg options like nostd and noalloc, and dealing with a lot of wrinkles in the language. Want to use a dyn trait? You'll need to make sure the trait doesn't have any functions with generic parameters or async; makes perfect sense, but adds tension; you want to avoid unnecessary runtime costs in the ideal case but still have the flexibility to use a dyn trait in other cases. Not to mention the borrow checker and how it interacts with a lot of these design choices. Go code is much dumber, but often times it's sufficient.

And that's the crux of it. Go is simple in a stupid way, rather than an elegant way, but it really makes the most of it. If you want to supplant Go at what it does best, trying to make a better programming language overall may be a bit misguided. It's probably not that hard to come up with a programming language design that is "better" than Go. What's hard, IMO, is coming up with a programming language where the cognitive load increase relative to Go is met with a pay-off that people using Go would consider genuinely worth it. Something like guaranteed data race safety is definitely good enough if it's something someone needs or at least strongly wants for a given use case. Sum types, on the other hand, are very nice thing to have that make modelling data easier and less error-prone, but not having them isn't exactly the end of the world... In Go, people sometimes emulate them with interfaces and type-switches, and it's not fantastic, but it's usually sufficient.

Ocaml probably could/should be more successful, but I'm not sure it competes with Go, I think they're in entirely different wheelhouses. Ocaml feels like it doesn't want to compete with Go, but then again, I only have relatively surface-level knowledge of Ocaml, so I can't really say for sure.

eru•27m ago
> Lack of sum types is probably one of the worst things about working in Go, and I think it is a much bigger problem than the lack of generics ever was.

Maybe, but once you have eg an Option or Either (a.k.a. Result) type, you typically really want to have some functions that work generically on all versions of them. (Though you could probably get away with using Go's version of void*, the empty interface, in a lot of cases?)

jchw•5m ago
Basically, anything that makes it possible to do an Etiher/Result type blows the whole damn thing up. It calls everything into question, e.g. whether multiple returns really makes sense. It's kind of a shame, because I would really like to be able to model things better (and ideally more efficiently too) when working in Go.
Taniwha•2h ago
Wirth was on the Algol68 committee - I'm sure he understood how those sorts of unions worked.

He also avoided a lot of the more advanced features of Algol68, he thought it too complex, when he designed Pascal

eru•30m ago
Alas, this one gives a 403 Forbidden.

https://archive.is/oTbMW works though.

Buttons840•27m ago
> But another thing Muratori points out is that is that Dahl and Nygaard copied the feature in safe working form into Simula, and Stroustrup knew about it and intentionally dropped it from C++, thinking it inferior to the encapsulation you get from inheritance. This is funny! Because of course C already had case #3 above -- completely unchecked/unsafe unions, they only showed up in 1976 C, goodness knows why they decided on that -- and the safe(ish) std::variant type has taken forever to regrow in C++.

This seems like a mistake. At the end of the day, a bunch of code and logic has to be written somewhere, and I think it's better done outside the data object, at least some of the time.

Imagine you have the classic Shape class / interface and someone wants to write some code to determine whether a Shape is happy or sad, based on their synesthesia, what are they suppose to do? I guess just add a happy_or_sad() method to the interface? Like, we're just going to pile--err, I mean, "encapsulate"--every possible thing that can be done with the data into the data object?

The OOP way is probably some Shape class hierarchy with a Shape superclass and a bunch of specific Square, Circle, Triangle, subclasses. So I guess you go and modify a dozen subclasses to add your happy_or_sad() method. And you're definitely going to have to fork the code because nobody wants to upstream your personal feelings about which Shapes are happy or sad.

It's better to have a sum type for your Shape and then everyone can put all their code and logic outside of the Shape itself, and the type system will ensure, at compile time, that no Shape variants have been missed, so refactoring is assisted by the type system.

eru•21m ago
Inheritance can simulate sum-types. You can also simulate sum-types via what OOP people would probably call a visitor pattern: you hand me call-backs for what to do in all the different cases, and some trusted piece of code that you implement once for the type, does the case distinction and calls the right call-back. (You can either hand over the call-backs as functions / function pointers, or you can implement them as member methods pure OOP style.)

They are all equivalent in principle, but some of them are a lot more annoying to work with, especially when you want to do a pattern matching over multiple values at the same time, or match on nested patterns.

Complete silence is always hallucinated as "ترجمة نانسي قنقر" in Arabic

https://github.com/openai/whisper/discussions/2608
44•edent•55m ago•12 comments

Global hack on Microsoft Sharepoint hits U.S., state agencies, researchers say

https://www.washingtonpost.com/technology/2025/07/20/microsoft-sharepoint-hack/
551•spenvo•1d ago•239 comments

Uv: Running a script with dependencies

https://docs.astral.sh/uv/guides/scripts/#running-a-script-with-dependencies
245•Bluestein•7h ago•71 comments

AI comes up with bizarre physics experiments, but they work

https://www.quantamagazine.org/ai-comes-up-with-bizarre-physics-experiments-but-they-work-20250721/
126•pseudolus•5h ago•44 comments

What went wrong inside recalled Anker PowerCore 10000 power banks?

https://www.lumafield.com/article/what-went-wrong-inside-these-recalled-power-banks
372•walterbell•12h ago•176 comments

NASA’s X-59 quiet supersonic aircraft begins taxi tests

https://www.nasa.gov/image-article/nasas-x-59-quiet-supersonic-aircraft-begins-taxi-tests/
52•rbanffy•2d ago•31 comments

Jujutsu for busy devs

https://maddie.wtf/posts/2025-07-21-jujutsu-for-busy-devs
118•Bogdanp•6h ago•110 comments

An unprecedented window into how diseases take hold years before symptoms appear

https://www.bloomberg.com/news/articles/2025-07-18/what-scientists-learned-scanning-the-bodies-of-100-000-brits
10•helsinkiandrew•3d ago•2 comments

Don't bother parsing: Just use images for RAG

https://www.morphik.ai/blog/stop-parsing-docs
235•Adityav369•13h ago•65 comments

AccountingBench: Evaluating LLMs on real long-horizon business tasks

https://accounting.penrose.com/
443•rickcarlino•13h ago•113 comments

TrackWeight: Turn your MacBook's trackpad into a digital weighing scale

https://github.com/KrishKrosh/TrackWeight
514•wtcactus•15h ago•128 comments

AI could have written this: Birth of a classist slur in knowledge work [pdf]

https://advait.org/files/sarkar_2025_ai_shaming.pdf
16•deverton•3h ago•14 comments

Losing language features: some stories about disjoint unions

https://graydon2.dreamwidth.org/318788.html
65•Bogdanp•3d ago•15 comments

Look up macOS system binaries

https://macosbin.com
21•tolerance•3d ago•2 comments

Workers at Snopes.com win voluntary recognition

https://newsguild.org/workers-at-snopes-com-win-voluntary-union-recognition/
80•giuliomagnifico•2h ago•3 comments

New records on Wendelstein 7-X

https://www.iter.org/node/20687/new-records-wendelstein-7-x
211•greesil•15h ago•89 comments

Erlang 28 on GRiSP Nano using only 16 MB

https://www.grisp.org/blog/posts/2025-06-11-grisp-nano-codebeam-sto
137•plainOldText•10h ago•8 comments

The Game Genie Generation

https://tedium.co/2025/07/21/the-game-genie-generation/
116•coloneltcb•12h ago•49 comments

The surprising geography of American left-handedness (2015)

https://www.washingtonpost.com/news/wonk/wp/2015/09/22/the-surprising-geography-of-american-left-handedness/
28•roktonos•9h ago•14 comments

We have made the decision to not continue paying for BBB accreditation

https://mycherrytree.com/blogs/news/why-we-have-made-the-decision-to-not-continue-paying-for-accreditation-from-the-better-business-bureau-bbb
77•LorenDB•3h ago•36 comments

What will become of the CIA?

https://www.newyorker.com/magazine/2025/07/28/the-mission-the-cia-in-the-21st-century-tim-weiner-book-review
84•Michelangelo11•12h ago•129 comments

Scarcity, Inventory, and Inequity: A Deep Dive into Airline Fare Buckets

https://blog.getjetback.com/scarcity-inventory-and-inequity-a-deep-dive-into-airline-fare-buckets/
96•bdev12345•11h ago•37 comments

Spice Data (YC S19) Is Hiring a Product Associate (New Grad)

https://www.ycombinator.com/companies/spice-data/jobs/RJz1peY-product-associate-new-grad
1•richard_pepper•9h ago

Tokyo's retro shotengai arcades are falling victim to gentrification

https://www.theguardian.com/world/2025/jul/18/cult-of-convenience-how-tokyos-retro-shotengai-arcades-are-falling-victim-to-gentrification
28•pseudolus•3d ago•9 comments

I know genomes. Don't delete your DNA

https://stevensalzberg.substack.com/p/i-know-genomes-dont-delete-your-dna
41•bookofjoe•11h ago•50 comments

Show HN: Lotas – Cursor for RStudio

https://www.lotas.ai/
65•jorgeoguerra•12h ago•26 comments

Occasionally USPS sends me pictures of other people's mail

https://the418.substack.com/p/a-bug-in-the-mail
167•shayneo•15h ago•167 comments

My favourite German word

https://vurt.org/articles/my-favourite-german-word/
34•taubek•2d ago•38 comments

I've launched 37 products in 5 years and not doing that again

https://www.indiehackers.com/post/ive-launched-37-products-in-5-years-and-not-doing-that-again-0b66e6e8b3
136•AlexandrBel•18h ago•118 comments

FCC to eliminate gigabit speed goal and scrap analysis of broadband prices

https://arstechnica.com/civis/threads/fcc-to-eliminate-gigabit-speed-goal-and-scrap-analysis-of-broadband-prices.1508451/page-2
187•Bluestein•7h ago•111 comments