> upon my discovery of pattern matching.
How is Erlang's pattern matching different from ML-like pattern matching? I only know Elixir, which is more or less the same as ML.
How is Erlang's pattern matching different from ML-like pattern matching? I only know Elixir, which is more or less the same as ML.
(* In OCaml *)
type t = A | B | C | D
match A with
| A | B -> "something"
| C | D -> "else"
And in elixir: case :a do
a when a in [:a, :b] -> "something"
a when a in [:c, :d] -> "else"
end
And of course, you lose exhaustiveness from type information, but that's a preference.But, more to the point, I think what GP's referring to is partial function definitions via pattern matching on the arguments. That is intoxicating, and I wish OCaml had that.