[m-users.] Compiler cannot infer determinism det when exhaustively pattern matching on a constant?

Anders Lundstedt mercury-users at anderslundstedt.se
Thu Aug 1 13:45:42 AEST 2024


Another minor thing:

> > ...
> > % accepted by compiler
> > p1(A, B) :- (A = c1, B = c2) ; (A = c2, B = c1).
> > ...
> > % compiler error
> > p3(A) :- (c = c1, A = c2) ; (c = c2, A = c1).
>
> According to the algorithm that the compiler uses to detect switches:
>
>         A disjunction is a switch if each disjunct has near its start
> a unification
>         that tests the same bound variable against a different function symbol
>
> By that criterion, p1 is a switch (and hence det) where A is the bound variable.
> The disjunct in p3 is not a switch because each disjunct begins with a
> conjunction.

In what sense does each disjunct of p3 begin with a conjunction while
each disjunct of p1 does not? Is not the problem rather that each
disjunct of p3 has not “near its start a unification that tests the
same bound variable against a different function symbol” (which each
disjunct of p1 has)?


More information about the users mailing list