3 ms·
I didn't recall anything like ADTs in Pascal, but I last used it a very long time ago, so I dug into it. A "record with variant part"[1] seems to be equivalent
by noelwelsh 2y ago
I didn't recall anything like ADTs in Pascal, but I last used it a very long time ago, so I dug into it. A "record with variant part"[1] seems to be equivalent in expressive power to ADTs. However Pascal lacks the other part of the equation, which is the guarantees when taking apart such a type that you will handle all cases, a.k.a exhaustivity checking. In general, I think too much material focuses on the data defining part of algebraic data types, and not the data using part, known as strucural recursion, which is arguably more useful. (You tend to use data more than you define it.)
It's also interesting that more "modern" libraries have forgotten these lessons. E.g. Python and Go have nothing like algebraic data types.
[1]: https://www.freepascal.org/docs-html/ref/refsu15.html https://www.freepascal.org/docs-html/ref/refsu15.html
- weinzierl 2y agoThere is also a stand alone sum type called Variant. https://www.freepascal.org/docs-html/ref/refse18.html#x45-650003.7 https://www.freepascal.org/docs-html/ref/refse18.html#x45-65...
- noelwelsh 2y agoI think that's more like an any type, as you can assign any value to it. A sum type can only take on values that are defined at the time the sum type is defined.