[mercury-users] Beginner question

Sandy Harris sandy at storm.ca
Wed Nov 8 17:07:09 AEDT 2000


The boolean library module has:

:- type bool ---> no ; yes.

:- pred bool__or(bool, bool, bool).
:- mode bool__or(in, in, out) is det.

:- pred bool__and(bool, bool, bool).
:- mode bool__and(in, in, out) is det.

So far so good, but what other mode declarations could be added?
One could just say:

:- mode bool__or(in, out, in) is nondet.
:- mode bool__and(in, out, in) is nondet.

but that seems to lose some information. Can you instead say
something like:

:- mode bool__and(no, out, yes) is failure.
:- mode bool_or(yes, out, no) is failure.

since, in C notation, there is no x such that 0 & x == 1
or 1 | x == 0

and then have:

:- mode bool__and(yes, out, in) is det.
:- mode bool_or(no, out, in) is det.

since x & 1 == x and x | 0 == x for all x.

:- mode bool__and(no, out, no) is multi.
:- mode bool__or(yes, out, yes) is multi.

since 0 & x == 0 and 1 | x == 1 for any x.

Methinks adding this detail might help with complex inferences
about booleans, but I'm not sure how to do it or even if it is
possible.

XOR has more convenient modes:

:- pred bool__xor(bool, bool, bool).
:- mode bool__xor(in, in, out) is det.
:- mode bool__xor(in, out, in) is det.
:- mode bool__xor(out, in, in) is det.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list