[mercury-users] newbie question on negation
Prashanth
prash.n.rao at gmail.com
Sun Sep 16 22:26:10 AEST 2012
Hi list,
I have come to understand that negation in Mercury is complicated -- to
my newbie mind. The code below prints out the names of all the "happy"
entities.
%%%%%% START %%%%%
:- module kb0.
:- interface.
:- import_module io.
:- pred main(io, io).
:- mode main(di, uo) is det.
:- implementation.
:- import_module solutions.
:- type entity == string.
:- func j = entity.
j = "joe".
:- func m = entity.
m = "moe".
:- func l = entity.
l = "larry".
:- pred happy(entity).
:- mode happy(out) is multi.
happy(E) :-
E = j;
E = l.
%% alternative
% happy(j).
% happy(l).
main(!IO) :-
solutions(happy, Xs),
io.write_list(Xs, "\n", io.write_string, !IO),
io.nl(!IO).
%%%%%% END %%%%%
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.
2. How do I get it to print ALL entities that is not happy? I figure I'd
have to create a list of all entities and then use "list.negated_filter"
on it. So, how do I get a list of all entities, without creating it with
"Es = [j, m, l]"? By the way, the manual says about
"list.negated_filter" that "X is included in FalseList iff Pred(X) is
true." I guess that is a bug in the manual.
Thanks!
Prashanth
--------------------------------------------------------------------------
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