[erlang-questions] Missing compile warning
Richard A. O'Keefe
ok@REDACTED
Mon Mar 3 22:42:24 CET 2014
On 4/03/2014, at 6:16 AM, Vlad Dumitrescu wrote:
>
> I'm not sure if I can agree with this. Non-matchable clauses should in my opinion be marked as errors, because they expose a logical flaw (usually a misordering of the clauses), and in this case I would have them be 100% accurate.
Consider a function with two clauses.
f(X, ...) when G1 -> B1;
f(X, ...) when G2 -> B2.
where X, ... stands for the same sequence of distinct
variables in both clauses.
The second clause is unmatchable iff G1 and G2 are
equivalent. Now G1 and G2 may contain arithmetic
expressions, let's say they are E1 > 0 and E2 > 0
respectively.
If memory serves me correctly, determining whether
two arbitrary arithmetic expressions are equal is
unsolvable.
If I'm wrong about that, let G1 and G2 be Boolean
expressions. Determining whether G1 and G2 are
equivalent is then the standard NP-complete problem.
There are clearly going to be some special cases
that can be handled: guards that are pure
conjunctions (,) of type tests and
Variable Relop Constant should be doable, for example.
It might be an interesting research project for someone
to determine the exact complexity of determining when
one Erlang guard implies another.
If user-defined guards were ever admitted into Erlang
the task would become obviously impossible.
More information about the erlang-questions
mailing list