[mercury-users] Beginner question

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 8 18:04:04 AEDT 2000


On 08-Nov-2000, Sandy Harris <sandy at storm.ca> wrote:
> 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?

Well, lots of other mode declarations *could* be added.
But which additional mode declarations would be generally useful?

> One could just say:
> 
> :- mode bool__or(in, out, in) is nondet.
> :- mode bool__and(in, out, in) is nondet.

It's possible to achieve the same effect by defining a predicate

	:- pred bool(bool).
	:- mode bool(out) is nondet.
	:- mode bool(in) is semidet.
	bool(true).
	bool(false).

and then using calls to `bool/1' whenever you want to
nondeterministically generate a boolean.
E.g. instead of

	bool__or(X, Y, Z)

you can write

	bool__or(X, Y, Z),
	% nondeterministically generate any remaining unbound values
	bool(X), bool(Y), bool(Z).

The compiler will then if necessary reorder the calls to `bool(out)'
so that they occur before the call to `bool__or'.

One could argue that this alternative way of writing it is clearer,
since it makes the nondeterministic generation more explicit.
So my inclination, in the absence of any convincing examples,
is to leave the current standard library unchanged.
If you have any good examples of why you'd want to use
`bool__or' and/or `bool__and' as a generator, please share them.

> 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.
>
> 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.

Yes, you can.  To make that syntax work, all you need to do is
to define the `yes' and `no' modes:

	:- mode yes == in(bound(yes)).
	:- mode no == in(bound(yes)).

Another way of writing it is as

	:- mode bool__and(in(bound(no)), out, yes) is failure.
	:- mode bool__or(in(bound(yes)), out, no) is failure.

or
	
	:- inst yes ---> yes.
	:- inst no ---> no.

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

However, I'm not sure that doing this in the standard library would be
useful.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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