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

Anders Lundstedt <[email protected]> Thu, 1 Aug 2024 05:03:41 +0200
Newsgroups gmane.comp.lang.mercury.general
Message-ID <CANGMbaY0d_ha15jEzMhVvP5Ro31kA_sExs68U2d0YjozaqXqUw@mail.gmail.com>
> 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
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users