3 ms·
Every language can do tagged unions with "kind" or "tag" markers and switch statement. But it's going to be verbose without pattern matching/destructuring combo
by panzerklein 7y ago
Every language can do tagged unions with "kind" or "tag" markers and switch statement. But it's going to be verbose without pattern matching/destructuring combo.
- bcherny 7y agoIt’s not that bad, to be honest. Maybe a few more keystrokes than Haskell, but so is everything else in a C-style language. Definitely a fair point that it is a few more keystrokes, though.
- frankpf 7y agoThankfully TypeScript's type system is powerful enough (and JS's syntax flexible enough) to decently simulate pattern matching: https://gist.github.com/frankpf/cde7f792580f731dfe886ed2d91bab45 https://gist.github.com/frankpf/cde7f792580f731dfe886ed2d91b... (see the second file for usage)