Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Sum types, of course.


How do you expect to use sum types in assembly? Remember where C came from and why it was designed the way it was.


A naive sum type is just a tag plus a payload. There is no problem here. If you have enums you could have had sum types.

The historical argument and appeal to assembly is illogical here. The only real argument is that niche value optimization is too complex or too clever for the time so even if sum types were in C, nullable pointers would still exist either way.


I remember why C stayed what it is at least: elitism and gatekeeping. And YAGNI, repeated millions of times, of which only the first few were correct.

You're telling me OCaml / Rust / Haskell compile to fairy pixie dust? Obviously their compilers figured it out and it works.


> I remember why C stayed what it is at least: elitism and gatekeeping.

If that was the goal, it failed horribly - the gatekeeping didn't work because the popularity exploded.

> You're telling me OCaml / Rust / Haskell compile to fairy pixie dust? Obviously their compilers figured it out and it works.

I said nothing of the sort.


You asked how sum types work in assembly. I'm telling you that at least 3 compilers figured that part out.


> You asked how sum types work in assembly.

No, I didn't - I asked how sum types were supposed to work in an era of 64KB memory systems.


They don't need extra memory in Rust for the case of nullable pointers.

The boring cases require an enum tag in C too.

By bringing up the one thing that doesn't matter, your argument becomes purely ideological.


You're missing the point - give me a Rust compiler that can run and compile in 64KB memory, then you'll understand that the language C was constrained not just by what the output is running on, but by what the machines of the time could actually handle during compilation.


Borland's PASCAL did it on the IBM PC.

And which modern C compiler fits into 64KB? Even TCC needs 100KB. But that's beside the point. No machine of the last 36 (I'll push my chances, 40) years needs to fit a compiler in 64KB.


> Borland's PASCAL did it on the IBM PC.

That's famously a single-pass compiler. Rust is famously unable to compile in a single pass.

It is not possible to make a borrow-checking language that compiles in a single pass.

> No machine of the last 36 (I'll push my chances, 40) years needs to fit a compiler in 64KB.

Exactly - that's why C is what it is: it wasn't a mistake, they were working under the constraints of the time. My original comment (that you appeared to disagree with) said specifically "Remember where C came from and why it was designed the way it was."

Let me ELI5 it for you: It was specifically designed to emit assembly in a single pass because of the constraints of the time.

WTF does "Hur Dur Rust Goodest!" comments mean in this context?


> That's famously a single-pass compiler. Rust is famously unable to compile in a single pass.

I probably should have replied under the other comment. I was also referring to your

> No, I didn't - I asked how sum types were supposed to work in an era of 64KB memory systems.

But context got lost between replies.

> that's why C is what it is

C famously had a big redesign in 1990. The language of today isn't the same K&R printed.


Pascal had pointers? They could be `nil` too https://www.freepascal.org/docs-html/ref/refse15.html


The thread talked about sum types, which apparently appeared on ALGOL; although I don't know how much memory did an ALGOL compiler need.


How are you going to build sum types in a way where you can interact with assembly or machine code? The CPU doesn't know about that stuff


OCaml / Rust / Haskell.

Apparently they found a way to have the CPU know... about "this stuff".


Sum types map down to reading a tag and doing a comparison against fixed values.

I don't know what to tell you, but you're clearly not cut out to be a software developer in either machine code, assembly or C or any other language if you don't understand something this basic.


Please check your tone down, I'm arguing politely with you but apparently you're so wrapped up in this that you're resorting to ad hominems.

Sum types aren't the be all end all to all issues, for example you can not representer pointer values efficiently with sum types. Even rust does not wrap up pointers with sum types. Now try to go back 37 years to C89 and ask yourself if they were going to require compilers to have stringent checks like the rust compiler does.


Nobody claimed that "sum types are be all end all". I originally responded to "how would you handle cases where a value is unset without NULL" with "sum types" which are trivially presentable with bit masks if memory usage is of big concern (and nowadays in 99.9999% of the cases it genuinely is not).

And, tagged unions are a thing and were a thing for a long time.

Of course it's too late to change all this today; it would have been too late even 20 years ago. But outside of f.ex. Linux kernel and some other super hardcore C libraries, a lot can be done for the world to migrate to safer constructs and away from sentinel values. And that's what languages like Rust do.

Super memory constrained environments have not been the mainstream programming work for decades and now remain limited to embedded / IoT. Not sure what the reservation against sum types is these days.


Yeah and I was trying to explain that sum types don't work for pointers, without a significant performance hit.

No one here is saying C is a great design, but in the context of 60 years ago, it worked out pretty well, and all the language which had additional runtime complexity (Pascal of course, but also Ada and FORTH) struggled because they didn't dial the right level of complexity


That's unnecessarily rude, and untrue in any case. Everyone has to learn stuff sometime, and most people won't naturally run into the implementation details of how higher level languages get translated into machine code.


I agree his tone was not productive but the comment he responded to seemed like a disingenuous argument as well. "The CPU doesn't know about that stuff" is not true -- or it's arguing in bad faith. I mean, hello, tagged unions, all of us with some experience can write a C program that works with those. It's 100% false to say what he said.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: