[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:03:41 AEST 2024
> 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
Thanks for this! Just out of curiosity: what is the exact meaning of
“near its start” here?
> If you rewrite p3 to be:
>
> p3(A) :- (c = c1, A = c2 ; c = c2, A = c1)
>
> it will also not be detected as a switch
Did you mean something else or is this rewrite really more than
syntactically different from my p3? My p3:
p3(A) :- (c = c1, A = c2) ; (c = c2, A = c1).
(Remove the inner parentheses to get your rewrite. But the comma bind
more tightly than the semicolon and thus there should be no
difference?)
> However,
>
> p3(A) :- C = c, (C = c1, A = c2 ; C = c2, A = c1).
>
> is a switch.
Thanks, this is certainly a convenient solution.
Anders
More information about the users
mailing list