[m-dev.] for review: allow separate mode decls for zero arity preds

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 8 03:03:29 AEST 1999


On 06-Sep-1999, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> 
> > Estimated hours taken: 0.75
> > 
> > compiler/make_hlds.m:
> > 	Don't add a default mode for predicates with zero arity
> > 	and no pred or mode declaration.  The rationale is that
> > 	there's no compelling reason to add a default mode, since
> > 	the mode will be inferred anyway, if it is used,
> > 	and adding a default mode breaks some existing code,
> > 	e.g. extras/clpr/samples/tests.m, which assumes that
> > 	a predicate that is not called and which has zero arity and
> > 	no pred or mode declaration need not be mode-correct.
>  
> I don't think this is a good assumption for that code to be making. If
> there is only one mode which can be inferred I don't see any good reason
> not to infer it and do full error checking even if the code is not used.
> There's no point adding the code if it isn't going to be used sometime.

Code which is used in assertions need not have any modes or be mode-correct.

For assertions, it is useful to be able to write predicates and functions
which do not have any modes.  For predicates of arity > 0, this is trivial.
For functions, it is not obvious how to do it, because functions get a
default mode.  But in fact it is possible to override it using something
like this

	:- mode foo(in(not_reached), in(not_reached), ...) = in(not_reached).

which will be mode-correct no matter what the mode of `foo' is.
For zero-arity predicates (these are sometimes known as "propositions"),
due to an accident of syntax if you give a pred declaration then this
also acts as a mode declaration.  And the `not_reached' trick doesn't work
since there are no arguments to attach the `in(not_reached)' mode to.
That means there's currently no way to give no mode for a zero-arity predicate
except by leaving off the predicate declaration.  That already is a bit
unfortunate.  Your change would exacerbate that situation.

Hmm, how about the following alternative?
We could say that a `:- pred' declaration for a zero-arity predicate implies
a corresponding mode declaration only if there is a determinism annotation
on the pred declaration.  That would both (a) avoid the need for
special-casing zero-arity predicates when generating Mercury code, and
(b) solve the problem mentioned above, by giving a way to declare
zero-arity predicates with no modes.

With this alternative, the following declarations would have the semantics
specified in the corresponding comments:

	% foo has no modes, or the modes for foo will be inferred.
	:- pred foo.

	% bar has one mode, with determinism semidet.
	:- pred bar is semidet.

	% baz has one mode, with determinism semidet.
	:- pred baz.
	:- mode baz is semidet.

	% quux has one mode, whose determinism will be inferred.
	:- pred quux.
	:- mode quux.

Comments?

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list