[erlang-questions] erlang *****
Richard A. O'Keefe
ok@REDACTED
Mon Mar 17 01:16:27 CET 2008
On 15 Mar 2008, at 12:57 am, Andras Georgy Bekes wrote:
> Why don't we extend the notion of patterns to somehow describe the
> union
> set operation?
Consider
f(a\/b, a\/b, ..., a\/b) -> ...
If f has n arguments, this expresses 2**n matches.
At first sight, this is great. Expressiveness is always nice.
But there is a question about how costly it is.
At second glance, what's the problem? We match one argument,
then move on. But now consider
f({X,_}\/{_,X},
{Y,X}\/{X,Y},
...
{Z,W}\/{W,Z}
)
I don't have a proof, but my gut feeling is that the combination
of compiling and executing clauses with "or" patterns has to be NP.
So this most definitely does "ruin efficiency".
You could hack around this by requiring that if a head variable is
bound in a disjunctive pattern it is not matched by any other head
pattern. But there are limits to the artificial restrictions that
are tolerable. If you want each pattern to commit as soon as it has
matched, then I believe you have to define the order in which the
patterns are matched, which is not something Erlang has hitherto needed.
I note that my abstract pattern proposal *already* gives you disjunctive
patterns, BUT in such a way that the disjunctions can't interact like
this.
More information about the erlang-questions
mailing list