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

Anders Lundstedt mercury-users at anderslundstedt.se
Thu Aug 1 03:56:06 AEST 2024


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


More information about the users mailing list