Hasty Briefsbeta

Bilingual

Losing language features: some stories about disjoint unions

10 months ago
  • #sum-types
  • #history
  • #programming-languages
  • Sum types (disjoint unions, tagged unions, safe variant types) are essential and widely adopted in modern languages like ML, Haskell, Rust, Swift, and Scala.
  • Proper implementation of sum types requires coupling a tag with an unsafe union and enforcing access via syntactic constructs like switch/match expressions.
  • Three common degenerate implementations of sum types: unguarded access leading to runtime errors, advisory tags without runtime checks, and no tags at all.
  • Casey Muratori's talk highlights the early origins of safe disjoint unions in the 1960s, predating ML, and their adoption in Simula.
  • C++ initially omitted safe variant types, favoring inheritance, leading to the later reintroduction of std::variant.
  • Mesa, a PARC project, featured safe variant types, but Modula 2, influenced by Mesa, implemented them incorrectly due to Wirth's oversight.
  • Language features often get broken, mis-copied, or omitted due to designer biases, showing the circuitous nature of progress in programming languages.