Huh? They're part of Pascal (known as variant records) and plenty of other languages besides. It's mostly C that lacks them, and even then you're just expected to implement them yourself, for maximum efficiency.
"plenty of other languages besides" doesn't matter if those languages aren't being used in practice.
Let me list off the top 10 languages (incl markup) from the most recent Stack Overflow survey, specifically the Professional Developers tab. https://insights.stackoverflow.com/survey/2019#technology-_-...
* JavaScript
* HTML/CSS
* SQL
* Python
* Java
* Bash/Shell/PowerShell
* C#
* PHP
* TypeScript
* C++
You can argue about the demographics of Stack Overflow or the bias in users who actually respond on these surveys or a million other things. But based on job postings I've seen in the last several years, I'd wager this list is pretty accurate.
But it was a response to the following comment:
> > I could not believe they had not been part of any prior language I'd learned.
> Huh? They're part of Pascal (known as variant records) and plenty of other languages besides. It's mostly C that lacks them, and even then you're just expected to implement them yourself, for maximum efficiency.
With the context of that post, I hope you would understand that I am disagreeing with the insinuation that every programmer has used "Pascal [...] and plenty of other languages besides". You can easily learn five different languages and finally end up in Haskell without having encountered ADTs before.
It sounds like GP is saying they had never used of those languages beforehand. I'm not sure why would be so surprising given that it doesn't accompany any other information like "and I had used 20 other languages before it".
Just enable -Wincomplete-patterns or -Wall!
For example if you write this in Haskell
data PrimaryColor = Red | Green | Blue
colorToInt Red = 1
colorToInt Green = 2
colorToInt Blue = 3
it is closed because future code can't add more alternatives. Instead you must simulate it using type classes, with a wildly different syntax, and (some would say) a hack. Or define a different sum type that wraps the above.OCaml on the other hand supports the above perfectly with a slightly different syntax, but it also supports polymorphic variants (not to be confused with a Haskell sum type that's polymorphic because of a type variable like Maybe) which are lighter weight. For example you can write a function that takes different "constructors" without necessarily giving a definition for the type or listing all alternatives:
let color_to_int = function
| `Red -> 1 | `Green -> 2 | `Blue -> 3
Notice I never defined any type for the three colors! If you wish, you can mention the type: [< `Red | `Green | `Blue ]
or give it an alias to make it look more normal. But you can add (with some limitations) or remove more things to this variant later on.To me, though, the most intuitive way of understanding this is to think of the first as nominal typing, whereas the second is structural typing.
(Now with optional laziness.)
Here the Rust book mentions it:
> async bodies and other futures are lazy: they do nothing until they are run.
https://rust-lang.github.io/async-book/03_async_await/01_cha...
I just read it, and thought it was odd. I don't understand how Rust's async relates to a laziness as in Haskell's laziness.
All of these things build up some form of computation that doesn’t execute until later. Until then, they’re represented by some kind of data structure.