3 ms·
> No, switch is not like a special case of match. Sure is. Or a degenerate one if you prefer. > match is a reducible structured control-flow construct whose p
by masklinn 9y ago
> No, switch is not like a special case of match.
Sure is. Or a degenerate one if you prefer.
> match is a reducible structured control-flow construct whose power comes from destructuring.
Match on sum types with no associated data and you have a switch.
> match is much, much more like an if-else chain than a switch.
Depends on what you're matching.
- edflsafoiewq 9y agoNo it isn't. Again, switch can build irreducible control flow, match cannot. This code switch (x) { case 0: while (i < l) { s *= i; case 1: i += 1; } } cannot be rewritten with a simple match. You'd have to reloop the CFG.