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

Julien Fischer jfischer at opturion.com
Thu Aug 1 14:34:37 AEST 2024


On Thu, 1 Aug 2024 at 13:46, Anders Lundstedt
<mercury-users at anderslundstedt.se> wrote:
>
> 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)?

Ignore me there, I'm talking nonsense.  The issue, as I mentioned elsewhere,
is the function call to c/0.

Julien.


More information about the users mailing list