[mercury-users] newbie question on negation

Richard O'Keefe ok at cs.otago.ac.nz
Mon Sep 17 08:15:34 AEST 2012

On 17/09/2012, at 12:26 AM, Prashanth wrote:

The fundamental issue with negation is that many data structures have
infinitely many instances, so that if p(X) has finitely many solutions
not p(X) will have infinitely many.

> Given that I don't want to write "unhappy(E) :- m.", my questions are:
> 1. How do I get it to print ONE entity that is not happy? I tried "not happy(X), io.write_string(X, !IO)" but on further reading, discovered how the Goal for the "not" becomes part of an "if then else", and that the scope of X does not extend to the else.

You have got to generate values for X explicitly and then test them.

:- pred clown(entity).
:- mode clown(out) is multi.

clown(E) :- E = "j" ; E = "m" ; E = "l".

:- pred unhappy_clown(entity).
:- mode unhappy_clown(out) is multi.

unhappy_clown(E) :- clown(E), not happy(E).

(Seeing "moe" and "larry" I was expecting "curly", not "joe".)

> 2. How do I get it to print ALL entities that is not happy?

You really do NOT want to be defining entities to be strings,
because presumably the strings "", "a", "aa", "aaa", "aaaa", ...
are not happy.

As a rule of thumb, if there a small finite set of values
you are interested in, do not use strings for that.

mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list