Every Mercury predicate or function has exactly two purity values associated with it. One is the declared purity of the predicate or function, which is given by the programmer. The other value is the inferred purity, which is calculated from the purity of goals in the body of the predicate or function.
A predicate is declared to be impure or semipure by preceding the word
pred in its
pred declaration with
Similarly, a function is declared impure or semipure by preceding the
func in its
func declaration with
That is, a declaration of the form:
:- impure pred Pred(Arguments…). :- semipure pred Pred(Arguments…).
:- impure func Func(Arguments…) = Result. :- semipure func Func(Arguments…) = Result.
declares the predicate Pred to be impure and the function Func to be semipure, respectively.
Type class methods may also be declared as
semipure by preceding the word
func with the
appropriate purity level. An instance of the type class must provide
method implementations that are at least as pure as the method