[mercury-users] Hi, and determinism

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 29 12:00:56 AEDT 2001

On 29-Jan-2001, Thomas Conway <conway at cs.mu.OZ.AU> wrote:
> On Mon, Jan 29, 2001 at 10:08:54AM EST, Dan Sheppard wrote:
> > I try to avoid cascades of semidet predicates for these two reason
> > (which are really a minor recurrance of the prolog "no" problem), I
> > wonder if there's some other way of dealing with them? Perhaps there
> > are programming styles within the existing language I have failed to
> > notice which would help alleviate these problem?
> One thing you can do in many cases is make your predicates det and
> return a bool.

Another alternative along these lines is to use functions returning bool.
If the boolean is the only output, then this is a preferable alternative, IMHO.
Instead of

> :- pred has_prop(my_structure, bool).
> :- mode has_prop(in, out) is det.
> has_prop(f(...), yes) :-
> 	....


	:- func has_prop(my_structure) = bool.

	has_prop(f(...)) = yes :-

Note that you don't need to declare the mode or determinism, since for
functions you can just use the default `(in, in, ...) = out is det'.
So this is slightly more concise.

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