Remix.run Logo
zokier 3 days ago

ADTs are just structs and tagged unions. Tbh I don't understand why there is such fetishization of them considering how mudane they are.

aiono 3 days ago | parent | next [-]

That's the point I tried to make. All my bachelor education there was no single mention of sum types even though we learned about the visitor pattern. Instead of having to model sum types with object hierarchies, the language should provide a straightforward way to represent them since it's a very basic concept. I think that while things have improved a lot compared to past, sum types concept is still not known as much as objects for instance. Today all mainstream languages added direct support for sum types but awareness of it lacks.

3 days ago | parent [-]
[deleted]
Munksgaard 3 days ago | parent | prev | next [-]

They are not "just structs and tagged unions". The language support that enforces safe usage is not optional.

lock1 3 days ago | parent | prev [-]

And OOP is just subtyping and visibility modifiers too! /j

The main problem with ADT is language support for them. Primarily sum types, as they're missing in a lot of major PLs, while product types are "just" structs or classes.

Without language support, you can simulate them via brittle workarounds like `if (d.isTypeA()) return d.methodA()`.

Actually, I agree, it is mundane. That's exactly why it's kind of becoming an itch for anyone used to ADT, you'll feel like you're missing a basic building block.

Just imagine if all languages removed `struct`-like and `class`-like construct. Something like Brainfuck esolang or any plain asm. It certainly possible to create arbitrary complex program in those languages. But would you pick `struct`-less language over language that supports it natively?