> Niklaus Wirth uses “discriminated union” why Pascal doesn’t have sum types.
In the referenced paper (Wirth, 1975, An assessment of the programming language PASCAL, ACM), Wirth refers to the "inspect when" statement of Simula 67, which is structurally identical to type discrimination with (exhaustive) pattern matching; so Simula essentially already had something like "sum types" (unified with inheritance). Wirth implemented the same concept in his later Oberon language (which also supports inheritance and offers a WITH statement similar to Simula's "inspect when"). Also Pascal variant records are similar to sum types (even if Wirth didn't use this term); variant records have an explicit tag field, though Pascal doesn't enforce tag nor exhaustiveness checking. Wirth improved this in Oberon, which can be used to meet both key guarantess of sum types.
> Sum types are relatively rare in modern programming languages, outside functional programming and some places like Rust.
This claim always bugs me. “Sun types” have been a common idiom under different names since at least the 1970’s, and are supported by every major language in common use. Just not usually at the language / compiler level.
Interesting article, thanks for sharing.
> Niklaus Wirth uses “discriminated union” why Pascal doesn’t have sum types.
In the referenced paper (Wirth, 1975, An assessment of the programming language PASCAL, ACM), Wirth refers to the "inspect when" statement of Simula 67, which is structurally identical to type discrimination with (exhaustive) pattern matching; so Simula essentially already had something like "sum types" (unified with inheritance). Wirth implemented the same concept in his later Oberon language (which also supports inheritance and offers a WITH statement similar to Simula's "inspect when"). Also Pascal variant records are similar to sum types (even if Wirth didn't use this term); variant records have an explicit tag field, though Pascal doesn't enforce tag nor exhaustiveness checking. Wirth improved this in Oberon, which can be used to meet both key guarantess of sum types.
> Sum types are relatively rare in modern programming languages, outside functional programming and some places like Rust.
This claim always bugs me. “Sun types” have been a common idiom under different names since at least the 1970’s, and are supported by every major language in common use. Just not usually at the language / compiler level.