[mercury-users] Idea for another handy convention (preds, this time).

David Overton dmo at cs.mu.OZ.AU
Thu Jul 27 09:04:52 AEST 2000


On Wed, Jul 26, 2000 at 09:10:39AM -0700, Ralph Becket wrote:
> The language specifies that a function
> 
> :- func f(A, B, C) = Z.
> 
> lacking a mode declaration is assumed to have the conventional
> mode, namely
> 
> :- mode f(in, in, in) = out is det.
> 
> This is especially handy for function lambdas.
> 
> I would like to propose a similar default for preds, namely
> that a predicate
> 
> :- pred p(A, B, C).
> 
> lacking a mode declaration is assumed to have the conventional
> (in most other languages) mode of
> 
> :- mode p(in, in, in) is semidet.
> 
[...]
> 
> The default for functions is to only require explicit mode
> declarations when something `unusual' is going on; I propose
> we extend this idea to predicates as well.

IMHO, a predicate that does not have the mode/determinism
`p(in, ..., in) is semidet' is a lot less `unusual' than a function
that does not have mode `f(in, ..., in) = out is det'.  E.g. at least
95% (conservative guess) of the predicates I write have at least one
output argument and determinism `det'.

Also, currently when there is no mode declaration for a predicate,
this is an indication that the compiler should try to infer the
mode(s) for that predicate (it can presently only do this for
predicates that aren't exported from a module).

However, since we don't do mode inference of lambda expresssions,
perhaps `pred(in, ..., in) is semidet' would be a reasonable default
for these, especially since they are the kinds of predicates you are
most likely to use if programming in a functional style, as in the
example Ralph gives of `list__filter'.


David
-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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