[m-users.] Compiler cannot infer determinism det when exhaustively pattern matching on a constant?
Anders Lundstedt <[email protected]> Wed, 31 Jul 2024 19:56:06 +0200
| Newsgroups | gmane.comp.lang.mercury.general |
|---|---|
| Message-ID | <CANGMbaY7sm_LCVu+u8OVB4QS=QOXaOCkJE5SszBjNVGyLjKetQ@mail.gmail.com> |
Dear all, I try to define a predicate by exhaustive pattern matching on a constant. The compiler complains: “determinism declaration not satisfied. Declared `det', inferred `nondet'.” Why? Example code below, showing what fails (the predicate p3) and also showing a workaround (the predicate p2, using helper predicate p1): :- module test. :- interface. :- type t ---> c1; c2. :- pred p1(t::in, t::out) is det. :- pred p2(t::out) is det. :- pred p3(t::out) is det. :- implementation. :- func c = t. c = c1. % accepted by compiler p1(A, B) :- (A = c1, B = c2) ; (A = c2, B = c1). % accepted by compiler p2(A) :- p1(c, A). % compiler error p3(A) :- (c = c1, A = c2) ; (c = c2, A = c1). Best regards, Anders Lundstedt _______________________________________________ users mailing list [email protected] https://lists.mercurylang.org/listinfo/users