Mostly out of curiosity: Which languages that are not solely functional (I'm also interested in multi-paradigm languages - I know that Ocaml and F# are ML dialects with OO added, so they inherit the algebraic data types from ML) have algebraic data types (or something similar) and pattern matching?
They can be kind-of emulated using enum
s and union
s (as in C, C++, ...more?) but this soon gets cumbersome and ugly, and the compiler can't warn you if you forget a case in your pattern matching or (much more propable, and much more dangerous) when accessing the union "in wrong ways", i.e. you ask for a field of a Left
value when it's actually a Right
value (what you get then is a meaningless reinterpretation of the bits that happen to be there).
I've heard that Pascal has something like tagged unions (link) and the Cyclone language supports tagged unions, too. Wikipedia also mentions Ada and Algol. Any other languages?
(In case you never heard of algebraic data types, you can read the accepted answer of "What is 'Pattern Matching' in functional languages?" for an excellent introduction)