Re:Why Typing Erlang is Hard: Standard Erlang
by amw-zero on Saturday November 07, 2020 @08:33AM
(#25014968)
What’s special about Erlang pattern matching? Haskell
and ML are at least equivalent.
[ Parent
| on HN ]
Re:Why Typing Erlang is Hard: Standard Erlang
by qqwy on Saturday November 07, 2020 @11:35AM
(#25016040)
They are not equivalent, as Erlang/Elixir uses structural typing whereas Haskell/ML uses nominal typing.
In Erlang you can define the following:
equal(X, X) -> true;
equal(_, _) -> false.
In Haskell, the following does not compile: equal x x = True
equal _ _ = False
instead, we need to write something like equal x y | x == y = True
| otherwise = False
A subtle difference, but in some cases the structural semantics really do make patterns a lot cleaner (shorter without sacrificing readability).
I think that this style of pattern-matching semantics is a consequence of Erlang's roots in Prolog, which works similarly (and not only checks for structural equivalence but even does unification when necessary).