With pattern matching you'll get static checking if your matching is exhaustive. Impossible with an if ladder. Therefore they're not semantically equivalent.
type 'a myOption = Some of 'a | None
let f (Some x) = x*x
Gives this output: Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
NoneYour solution with type and value checks in an if ladder was called "dynamic typing" exactly for this reason - you select paths dynamically in the runtime without any static checks on soundness of this selection.
I wouldn't. Pattern matching is primarly a conditional, that's why I focused on if-else.
> We're talking about language features semantically equivalent to pattern matching, and, turns out, there are none.
Why would you think that pattern matching revolves around compile-time guarantees? It does not. It's primarly a conditional, everything else is an optional, additional effect. You can have pattern matching in dynamically typed languages (Lisp, Erlang).
No, that's run-time branch selection. Exactly as with pattern matching (`match .. with ..'), except the latter is more convenient.
> Seriously, you sound like, "why bother with Ocaml when JavaScript does the same thing?".
And you really think I consider elaborate constructions a better thing than concise pattern matching?