3 ms·
Someone just re-invented discriminated variants from Pascal.
by Animats 10y ago
Someone just re-invented discriminated variants from Pascal.
- pjmlp 10y agoThis seems to have become quite prevalent. Apparently the majority of CS degrees don't teach history of programming languages. On my language design lectures in the mid-90's we had to learn all major ones, all the way back to Fortran.
- Manishearth 10y agoThis really doesn't seem like a reinventing to me (from either the Rust or C++ side). "Reinventing" implies ignoring history in the way you mention. Tagged unions are prevalent in so many languages that the designers of both C++17 and Rust are bound to know about them. This is "borrowing" (or "stealing" :p). The original Rust was ML-like and had an OCaml compiler, so Rust's enums definitely descended from those. I can't talk for C++ for sure, but like I said it's common in so many languages that they're bound to have derived inspiration from them.
- pjmlp 10y agoI guess I was ranting a bit out of place....
- nickpsecurity 10y agoI agree with Manishearth. It looks like they're learning more than forgetting. The Rust history page indicated it cherry-picked good things from a number of languages. Looks like this is just another one they've evolved into a type-safe default. A Good Thing.
- jnbiche 10y agoAs someone pointed out elsewhere, Pascal's discriminated variants ("variant records") aren't typesafe, since the tag isn't checked before the variant is accessed. From Essential Pascal, 4th edition: "The use of a variant record type is not type-safe." The whole point of the article's discriminated unions/records in Rust and C++17 is type safety. Maybe this has been built into one of the newer Pascal descendants, but it hasn't been around for years and years. And embedded C programmers have been using these kinds of "unsafe" discriminated unions for years. That said, I do think Ada has had these kinds of actually typesafe variant records for quite a while. But again, Rust isn't making any claims to innovation. Even the language name ("Rust"), is a reference to the language being based on rusty old best practices.
- pcwalton 10y agoNone of us would claim to have invented them. Sheesh, we wrote the bootstrap compiler in OCaml :)